473,480 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PHP Audio Array?

6 New Member
Im still new to MySQL and know my way around PHP but not fully.

I'm creating a Audio Database that can be viewed here : http://elixclothing.com/connection.php

Im trying to figure out how to query all of the audio locations and put them in my media player which can be played according to which audio button is pressed.

I have a few ideas, I was wondering if I should move the audiolocation column to a new table so that I select them easier and not stress out my current table. Or follow something along the lines of this http://bytes.com/topic/php/answers/7...y-one-row-time

My current code is below:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Test</title>
  4. <script src="ac_quicktime.js" language="JavaScript" type="text/javascript"></script>
  5. </head>
  6. <body>
  7. <script type="text/javascript"> 
  8. function toggleVisibility() {
  9.     document.getElementById("toggleMe").style.display = "";
  10.     if(document.getElementById("toggleMe").style.visibility == "hidden" ) {
  11.         document.getElementById("toggleMe").style.visibility = "visible";
  12.     }
  13.     else {
  14.     document.getElementById("toggleMe").style.visibility = "hidden";
  15.     }
  16. }
  17. function toggleDisplay() {
  18.     document.getElementById("toggleMe").style.visibility = "visible";
  19.     if(document.getElementById("toggleMe").style.display == "none" ) {
  20.         document.getElementById("toggleMe").style.display = "";
  21.     }
  22.     else {
  23.         document.getElementById("toggleMe").style.display = "none";
  24.     }
  25. }
  26. </script> 
  27.  
  28. <table border="1" width="75%" cellpadding="2" cellspacing="2"> 
  29. <tr> 
  30. <td align="center">Cue Code</td> 
  31. <td align="center">Cue Title</td> 
  32. <td align="center">Cue Description</td> 
  33. <td align="center">Time</td>
  34. <td align="center"></td>
  35. </tr> 
  36. <br />
  37.  
  38. <?php
  39. mysql_connect("***", "***", "***") or die(mysql_error());
  40. echo "Connected to MySQL<br /><hr />";
  41. mysql_select_db("elixclot_music") or die(mysql_error());
  42. echo "Connected to Database<br /><hr />";
  43. $query = "SELECT * FROM tracks";
  44. $result = mysql_query($query) or die(mysql_error());
  45. while($line = mysql_fetch_array($result)) {
  46.  
  47.     //        Audio Player Begins
  48. echo "<div display='none' id='toggleMe' >
  49. <p>".$line['cue_code']."</p>
  50. <p>".$line['cue_title']."</p>
  51. <OBJECT CLASSID='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' WIDTH='290' HEIGHT='20'
  52. CODEBASE='http://www.apple.com/qtactivex/qtplugin.cab'>
  53. <PARAM name='SRC' VALUE=".$line['cue_code'].">
  54. <PARAM name='AUTOPLAY' VALUE='true'>
  55. <PARAM name='CONTROLLER' VALUE='true'>
  56. <EMBED src=".$line[audiolocation]." WIDTH='290' HEIGHT='20'
  57. AUTOPLAY='false' CONTROLLER='true'
  58. PLUGINSPAGE='http://www.apple.com/quicktime/download/'>
  59. </EMBED>
  60. </OBJECT>
  61.  </div>";
  62.    //        Audio Player Ends
  63.  
  64.  
  65.  
  66. echo "<td align='center'>".$line['cue_code']."</td>"; 
  67. echo "<td align='center'>".$line['cue_title']."</td>"; 
  68. echo "<td align='center'>".$line['cue_description']."</td>"; 
  69. echo "<td align='center'>".$line['time']."</td>";
  70. echo "<td align='center'><a href='#' onclick='toggleDisplay();'><img src='speaker_dark.gif' border=0></a>";
  71. echo "</tr>"; 
  72. }
  73. ?>
  74. </table>
  75. </body>
  76. </html>
Any help would be greatly appreciated.
Jun 4 '10 #1
11 1834
HaLo2FrEeEk
404 Contributor
I can help a little bit. First, I'm curious as to why you're using a separate div for each track, you don't need to do that. I'm also trying to figure out why you're using quicktime when you should instead use something like a flash-based player.

First off, you have to understand that you're setting multiple divs, all with the same ID. Your javascript is using the hard-coded ID "toggleMe" to show or hide the player div. Since they all have the same ID this causes issues. You should have each track in the database have it's own unique ID which you could append to the div's ID, for example:

track_id = 0
cue_code = OPUS10.013_12
cue_title = She'll Be The One ver. 2
cue_description = underscore
time = 01:48:00

Then your code would use that unique track_id as the div's ID:

<div id="toggleMe_0"...

then your javascript function toggleDisplay() would change to toggleDisplay(divID) and you'd replace all hardcoded instances of "toggleMe" to divID in the actual function, like below. I also made a variable named obj, so that you don't have to type the whole document.getElementById line so many times:

Expand|Select|Wrap|Line Numbers
  1. function toggleDisplay(divID) {
  2.   var obj = document.getElementById(divID);
  3.   obj.style.visibility = "visible";
  4.   if(obj.style.display == "none" ) {
  5.     obj.style.display = "";
  6.     } else {
  7.     obj.style.display = "none";
  8.     }
  9.   }
You are also forgetting to print an opening tag for a table row, you're only printing the closing tag which is making all of your information print on 1 row. The fix is easy:

Expand|Select|Wrap|Line Numbers
  1. //        Audio Player Ends
  2.  
  3.  
  4. echo "<tr>";
  5. echo "<td align='center'>".$line['cue_code']."</td>";
  6. ...
Just insert the echo "<tr>"; line before you start printing your table data tags.

One more thing, you should add "return: false;" (without the quotes) directly after your toggleDisplay() call in the onclick attribute, this will stop the link from actually navigating in the browser (yes, a # is still technically navigation.)

And again, you should look into a flash-based player, you can usually feed data to it through a javascript call and you'll only have to print one, plus Flash is more universal. Since I want you to do that instead of using Quicktime, I'm only going to point out a slight error in your audio player printing code in passing, because I don't think you should use it:

Expand|Select|Wrap|Line Numbers
  1. <PARAM name='SRC' VALUE=".$line['cue_code'].">
  2. [...]
  3. <EMBED src=".$line[audiolocation]." WIDTH='290' HEIGHT='20'...
For starters, the Object param src and the embed src should be the same thing, you're setting 2 different values. Secondly, you forgot the single quotes in the embed src:

$line[audiolocation]

Should be:

$line['audiolocation']

Anyway, I hope this gives you something to work with, let me know if yu have any more questions and I'll do my best to help!
Jun 4 '10 #2
xkrazykidx
6 New Member
@HaLo2FrEeEk
I really cant thank you enough! You have finally given me an intelligent response that relates to what I am trying to do. Ive spent so many times on other forums trying to get some help.

I have made the additions you recommended, also I do have a "ID" column in my table.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Test</title>
  4. <script src="ac_quicktime.js" language="JavaScript" type="text/javascript"></script>
  5. </head>
  6. <body>
  7. <script type="text/javascript"> 
  8. function toggleDisplay(divID) {
  9.   var obj = document.getElementById(divID);
  10.   obj.style.visibility = "visible";
  11.   if(obj.style.display == "none" ) {
  12.     obj.style.display = "";
  13.     } else {
  14.     obj.style.display = "none";
  15.     }
  16.   }
  17. </script> 
  18.  
  19. <table border="1" width="75%" cellpadding="2" cellspacing="2"> 
  20. <tr> 
  21. <td align="center">Cue Code</td> 
  22. <td align="center">Cue Title</td> 
  23. <td align="center">Cue Description</td> 
  24. <td align="center">Time</td>
  25. <td align="center"></td>
  26. </tr> 
  27. <br />
  28.  
  29. <?php
  30. mysql_connect("localhost", "elixclot_haywars", "mister") or die(mysql_error());
  31. echo "Connected to MySQL<br /><hr />";
  32. mysql_select_db("elixclot_music") or die(mysql_error());
  33. echo "Connected to Database<br /><hr />";
  34. $query = "SELECT * FROM tracks";
  35. $result = mysql_query($query) or die(mysql_error());
  36. while($line = mysql_fetch_array($result)) {
  37.  
  38.     //        Audio Player Begins
  39. echo "<div display='none' id='toggleMe_1' >
  40. <p>".$line['cue_code']."</p>
  41. <p>".$line['cue_title']."</p>
  42. <OBJECT CLASSID='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' WIDTH='290' HEIGHT='20'
  43. CODEBASE='http://www.apple.com/qtactivex/qtplugin.cab'>
  44. <PARAM name='SRC' VALUE=".$line['cue_code'].">
  45. <PARAM name='AUTOPLAY' VALUE='true'>
  46. <PARAM name='CONTROLLER' VALUE='true'>
  47. <EMBED src=".$line['audiolocation']." WIDTH='290' HEIGHT='20'
  48. AUTOPLAY='false' CONTROLLER='true'
  49. PLUGINSPAGE='http://www.apple.com/quicktime/download/'>
  50. </EMBED>
  51. </OBJECT>
  52.  </div>";
  53.    //        Audio Player Ends
  54.  
  55.  
  56. echo "<tr>";
  57. echo "<td align='center'>".$line['cue_code']."</td>"; 
  58. echo "<td align='center'>".$line['cue_title']."</td>"; 
  59. echo "<td align='center'>".$line['cue_description']."</td>"; 
  60. echo "<td align='center'>".$line['time']."</td>";
  61. echo "<td align='center'><a href='#' onclick='toggleDisplay(divID);'><img src='speaker_dark.gif' border=0></a>";
  62. echo "</tr>"; 
  63. }
  64. ?>
  65. </table>
  66. </body>
  67. </html>
But I want to switch to a flash player like you suggested. I did a quick Google search and found this http://www.flamplayer.com/, is this a good player to use? I was going for simplicity. Also an example for what I was going for was this site http://opus1.o1engine.com/

again THANK YOU! THANK YOU!
Jun 4 '10 #3
HaLo2FrEeEk
404 Contributor
That player would work, you'd just build a dynamic playlist in the format that the player reads.

And are you trying to build something exactly like that example site? Sorting by genre, artist, album, title, etc? That's quite a bit of work for somethig that's already been done to death.
Jun 5 '10 #4
xkrazykidx
6 New Member
Great ill start working on putting it together.

Unfortunately yes, im working with a start-up audio production company and this is how they want to organize their audio clips. They wanted their site to mimic Opus's site almost to the T.
Jun 5 '10 #5
HaLo2FrEeEk
404 Contributor
Looks like you've got quite a bit of work ahead of you then. You'll want to start by clearly defining, in your database, individual details about every track. Don't wait til later, do it now while there are only a few tracks to add the data to and not hundreds.
Jun 5 '10 #6
xkrazykidx
6 New Member
@HaLo2FrEeEk
Thanks for all your help! You have been great! I wish I would have came here first! Luckily I have told the other team members to work on a CSV with all the information about each track and I also gave them outlines :)

Thanks again!
Jun 6 '10 #7
HaLo2FrEeEk
404 Contributor
if you need it I've got a php script that can take a CSV file and translate it into an SQL query to mass import into a database, unless your database admin panel already lets you import a CSV.

Also, don't forget to mark a best answer : )
Jun 6 '10 #8
captainB
23 New Member
I was reading this thread out of interest, and I must say that I'm impressed with the effort shown by HaLo2FrEeEk to answer the question.

You elevate the quality of this forum!

Thanks!
Jun 6 '10 #9
xkrazykidx
6 New Member
@HaLo2FrEeEk
Hmm I tried out FlamPlayer its great but unfortunately does not accomplish the task I was looking for. It automatically adds tracks to a database but does not include all the extra fields which im guessing I would have to input manually.

Also If i would like to add a track to the page, example where a user clicks on the listen button. I wouldnt be able to link that one track as FLAM is more about making playlists.

Also my Database allows importing of CSV's but thanks!
This project is becoming daunting and it seems like im never going to be able to complete it.

HaLo2FrEeEk I was wondering if you have the time to explain a little more about the "ID" idea. That seems like its more fitting to what I would like to accomplish.

Thanks again for all your help.
Jun 6 '10 #10
HaLo2FrEeEk
404 Contributor
A few more things I'd like to touch on. It still looks like you're printing the player code for each individual track, when I click the little play icon for a song, it actually hides that track's player instead of making it visible.

You're also still forgetting to print your table row tag at the beginning of each track:

Expand|Select|Wrap|Line Numbers
  1. //        Audio Player Ends
  2.  
  3.  
  4. echo "<tr>";
  5. echo "<td align='center'>".$line['cue_code']."</td>";
  6. ...
You need to do that.

Other than that, looking good.
Jun 7 '10 #11
xkrazykidx
6 New Member
@HaLo2FrEeEk
Thanks Ill add the code when I get home, I think to better explain my issue is that I would like to display only 1 media player and when I click the play button it plays that table specific song. Im trying to finish this before friday...which is seeming impossible.

HaLo2FrEeEk you have been a great help so far thanks.

I am having a hard time passing the audiolocation to the audio player and making the player hidden so that when I click listen it displays the hidden player. Also if I click the next track to listen it should (Not hide the player) but just load up that track and play.

Edit: Made an advancement and changed my Code, hopefully this works. Im just having an issue with line 77.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Test</title>
  4. <script src="ac_quicktime.js" language="JavaScript" type="text/javascript"></script>
  5. </head>
  6. <body>
  7.  
  8. <script type="text/javascript"> 
  9. function toggleDisplay(divID) {
  10.   var obj = document.getElementById(divID);
  11.   obj.style.visibility = "visible";
  12.   if(obj.style.display == "none" ) {
  13.     obj.style.display = "";
  14.     } else {
  15.     obj.style.display = "none";
  16.     }
  17.   }
  18. </script> 
  19.  
  20. <?php
  21.   mysql_connect("***", "***", "***") or die(mysql_error());
  22.   echo "Connected to MySQL<br /><hr />";
  23.  mysql_select_db("elixclot_music") or die(mysql_error());
  24.   echo "Connected to Database<br /><hr />";
  25.   $query = "SELECT * FROM tracks";
  26.  
  27.   $result = mysql_query($query) or die(mysql_error());
  28. $line = mysql_fetch_array($result);
  29. ?>
  30.  
  31. <?php
  32.  
  33. $cue_id = $_GET['cue'];
  34.  
  35. if($cue_id == $line['cue_code'])
  36.     {    
  37.     $audioURL = $line['audiolocation'];
  38.     return $audioURL;
  39.     }
  40.  
  41. ?>
  42.  
  43.      //        Audio Player Begins
  44. echo "<div display='none' id='toggleMe' >
  45. <OBJECT CLASSID='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' WIDTH='290' HEIGHT='20'
  46. CODEBASE='http://www.apple.com/qtactivex/qtplugin.cab'>
  47. <PARAM name='SRC' VALUE=".$line['cue_code'].">
  48. <PARAM name='AUTOPLAY' VALUE='true'>
  49. <PARAM name='CONTROLLER' VALUE='true'>
  50. <EMBED src="<?php $audioURL; ?>" WIDTH='290' HEIGHT='20'
  51. AUTOPLAY='false' CONTROLLER='true'
  52. PLUGINSPAGE='http://www.apple.com/quicktime/download/'>
  53. </EMBED>
  54. </OBJECT>
  55. </div>";
  56.     //        Audio Player Ends
  57.  
  58.  
  59. <table border="1" width="75%" cellpadding="2" cellspacing="2"> 
  60. <tr> 
  61. <td align="center">Cue Code</td> 
  62. <td align="center">Cue Title</td> 
  63. <td align="center">Cue Description</td> 
  64. <td align="center">Time</td>
  65. <td align="center"></td>
  66. </tr> 
  67. <br />
  68.  
  69. <?php
  70.  
  71. while($line) 
  72.     {
  73. echo "<td align='center'>".$line['cue_code']."</td>"; 
  74. echo "<td align='center'>".$line['cue_title']."</td>"; 
  75. echo "<td align='center'>".$line['cue_description']."</td>"; 
  76. echo "<td align='center'>".$line['time']."</td>";
  77. echo "<td align='center'><a href="<?php echo '?cue='.$line['cue_code']; ?>" onclick='toggleDisplay();'><img src='speaker_dark.gif' border=0></a>";
  78.   echo "</tr>"; 
  79.   }
  80.  ?>
  81.   </table>
  82.    </body>
  83.    </html>
Jun 7 '10 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2244
by: nigel | last post by:
I'm trying to handle 16-bit .WAV format audio files. I've started with the code below (from pythonapocrypha.com). I can successfully read in the 16-bit code, using Numeric.fromstring, as they...
5
2579
by: Shelly | last post by:
I had a problem with uploading images in that some files did not have a type of "image/something" from the $_FILES which I used for my verification. Someone (THANK YOU) suggested using...
0
1773
by: daniel123456 | last post by:
Hi, I'm searching for an audio mixer class that can change the balance o the lines too. I already found the AudioMixerHelper (e.g http://forums.hostrocket.com/archive/index.php/t-16820.html...
2
2079
by: Gidi Morris via .NET 247 | last post by:
Hi, Is there a way to play audio using MCI (I preffer MCI, but if you know of any others I'll be greatful) from a Filestream? I mean, I have a filestream to an audio file, can I play the audio?...
2
7830
by: positivebalance41m | last post by:
I have been searching how to do sound capture (record audio input) in VB.NET for days now. I find some references to "winmm.dll" calls, but they give VB5 or VB6 examples which won't code convert...
6
1981
by: Quentin | last post by:
Hi, I want to save an audio stream into a circular file so that I only keep say the last hour's audio. Can anybody help? Cheers, Quentin
1
2344
by: mmc | last post by:
3 methods needs doing; wave1: This static method takes an AudioInputStream and gradually lowers and then raises the volume so that the new AudioInputStream appears to be constantly alerting in...
7
11761
by: ianenis.tiryaki | last post by:
well i got this assignment which i dont even have a clue what i am supposed to do. it is about reading me data from the file and load them into a parallel array here is the question: Step (1) ...
1
2169
Dököll
by: Dököll | last post by:
Greetings, Good buddies! I am for the first time, since I started learning VB, going to build an application I wanted to build for my first son, a language and activities program that will allow...
1
7857
by: ehsanch | last post by:
Hi i am writing a SOAP client, when using php 5 soap , it send this code and i get error : <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope...
0
7037
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7080
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6735
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6895
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5326
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
2992
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
176
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.