Welcome to Dream.In.Code
Become a PHP Expert!

Join 149,989 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,367 people online right now. Registration is fast and FREE... Join Now!




play music in php

 
Reply to this topicStart new topic

play music in php, looping problem to play music

chitara
26 Nov, 2006 - 01:51 AM
Post #1

D.I.C Head
**

Joined: 16 Dec, 2005
Posts: 74


My Contributions
Hello everybody!

In my jukebox there is a facility to select multiple audio tracks with checkbox. Then the selected tracks will play with my defined player one after another. But here when I select more then one track al the tracks play all together I am sending the code in below. Can anybody please help me regarding this????


CODE
<?php

include "../admin/include/db.php";


$file=$_GET['track'];
//var_dump($file);

if($file != null)
   {
      for($i=0; $i < sizeof($file); $i++)
      {
               $music = $file[$i];

    $result=mysql_query("select * from musiclibrary where music_no='$music'");
    
    while($row=mysql_fetch_array($result)){
        $play_no=$row['music_no'];        
        //$play=$row['file_name'];
        

    }
    
    $sql_result=mysql_query("select file_name from musiclibrary where music_no='$play_no'");
      
        while($rows=mysql_fetch_array($sql_result)){
        $play=$rows['file_name'];        
        
        
?>
<html>
<head>
<title>Player</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<div id="Layer1" style="position:absolute; width:300; height:300; z-index:2; left: -2px; top: -2px; background-color: #000000; layer-background-color: #000000; border: 1px none #000000">
  

<OBJECT ID="MediaPlayer" WIDTH=300 HEIGHT=300
   classid="clsid:22D6f312-B0F6-11D0-94AB-0080C74C7E95"
   STANDBY="Loading Media Player components"
   TYPE="application/x-oleobject"
   codebase="http://activex.microsoft.com">

  <PARAM NAME = "autostart" VALUE = "True" >
  <PARAM NAME = "filename" VALUE = "<?print $mdir."/".$play;?>" >

</OBJECT>

    
</div>

</body>
</html><?
        
}    
}//var_dump($music);
   }            
?>



Regards

[mod edit] please use the code tags.
User is offlineProfile CardPM
+Quote Post

snoj
RE: Play Music In Php
26 Nov, 2006 - 12:55 PM
Post #2

Fell off the face of the earth
Group Icon

Joined: 31 Mar, 2003
Posts: 3,325



Thanked: 9 times
Dream Kudos: 750
My Contributions
What I would do (since I have limited knowledge of how the PARAM stuff works with controlling music playback) is I'd have a Javascript array containing the song length + plus some dead space just to be sure the song finished playing. And then combine that with a setTimeout() to change the song.

And please use the code tags!
User is offlineProfile CardPM
+Quote Post

chitara
RE: Play Music In Php
26 Nov, 2006 - 10:29 PM
Post #3

D.I.C Head
**

Joined: 16 Dec, 2005
Posts: 74


My Contributions
may I have any help from you people????

This post has been edited by chitara: 27 Nov, 2006 - 04:05 AM
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Play Music In Php
27 Nov, 2006 - 05:38 AM
Post #4

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,301



Thanked: 101 times
Dream Kudos: 1275
My Contributions
I would try something a bit different from what hotsnoj said and have an ajax script run the playlist through a php script to see what the length of the songs were and place each one in a music play one at a time for a certain amount of time and have the php return the song length (in time) + 10 seconds to have for the next loop through the ajax script.

So it would work like so for the output:

CODE

<!-- song 0 is playing at the moment -->
<input type="hidden" name="timeout" value="song length">
<input type="hidden" name="song 1" value="somevalue">
<input type="hidden" name="song 2" value="somevalue">
<input type="hidden" name="song 3" value="somevalue">

<OBJECT ID="MediaPlayer" WIDTH=300 HEIGHT=300
classid="clsid:22D6f312-B0F6-11D0-94AB-0080C74C7E95"
STANDBY="Loading Media Player components"
TYPE="application/x-oleobject"
codebase="http://activex.microsoft.com">

<PARAM NAME = "autostart" VALUE = "True" >
<PARAM NAME = "filename" VALUE = "song 0s value" >

</OBJECT>


Then it would plug in and have this:

CODE
<!-- song 1 is playing at the moment -->
<input type="hidden" name="timeout" value="song length">
<input type="hidden" name="song 2" value="somevalue">
<input type="hidden" name="song 3" value="somevalue">

<OBJECT ID="MediaPlayer" WIDTH=300 HEIGHT=300
classid="clsid:22D6f312-B0F6-11D0-94AB-0080C74C7E95"
STANDBY="Loading Media Player components"
TYPE="application/x-oleobject"
codebase="http://activex.microsoft.com">

<PARAM NAME = "autostart" VALUE = "True" >
<PARAM NAME = "filename" VALUE = "song 1s value" >

</OBJECT>


And so on until the songs were all gone.
User is online!Profile CardPM
+Quote Post

chitara
RE: Play Music In Php
2 Dec, 2006 - 08:45 PM
Post #5

D.I.C Head
**

Joined: 16 Dec, 2005
Posts: 74


My Contributions
Hi BetaWar,

Thanks for your response. But I am clear what you are saying.

Would you please explian it more???

User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Play Music In Php
3 Dec, 2006 - 03:50 PM
Post #6

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,301



Thanked: 101 times
Dream Kudos: 1275
My Contributions
So you use ajax to do the work for you. Have a php script take the length of each song on the playlist when they are submitted, add 5 seconds to it, then have the script set up a javascript to take things over on the client side. Have it with each of the songs in a hidden field in a form, and after the time is up have it use ajax to plug the remaining songs into the php script and do everything over again.

Also have it so that if the songs have all been played to display a message like 'Playlist finished'. Ajax can do all of this and more as long as you know some of the basics.

Get the main script and have the ajax (javascript) form and song code all in the same area (which will be overwritten by the php in the ajax server side part). Have it submit the form first, and have it take the form and have a copy sent to another area of the page, then have it update the song info from the other part of the page and send everything back to the main area. As it loops through it will all be finished in the same way and you will always have 2 copies of the playlist.
User is online!Profile CardPM
+Quote Post

chitara
RE: Play Music In Php
3 Dec, 2006 - 11:41 PM
Post #7

D.I.C Head
**

Joined: 16 Dec, 2005
Posts: 74


My Contributions
hmm..... sounds so complecated.

ok let me try it first....:-(

If I failed then knock again.

Regards


User is offlineProfile CardPM
+Quote Post

chitara
RE: Play Music In Php
9 Dec, 2006 - 09:24 PM
Post #8

D.I.C Head
**

Joined: 16 Dec, 2005
Posts: 74


My Contributions
Hi BetaWar,
I failed to get the length of music file:-(

Would you pleasetell me how can I do that?


Regards
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Play Music In Php
9 Dec, 2006 - 10:40 PM
Post #9

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,301



Thanked: 101 times
Dream Kudos: 1275
My Contributions
Well if these are your audio files that you are uploadig to a server then you can view their length in a simple music or audio player, then when uploading and placing into a database simply add a row in the table for the file length. THat would be the easiest way to do it. Sadly I don't know of any program to do this for you...
User is online!Profile CardPM
+Quote Post

chitara
RE: Play Music In Php
9 Dec, 2006 - 11:08 PM
Post #10

D.I.C Head
**

Joined: 16 Dec, 2005
Posts: 74


My Contributions
but I m not storing the file into the database:-(

just kept the name over there.

So???

Are you storing the playtime manually???

This post has been edited by chitara: 9 Dec, 2006 - 11:10 PM
User is offlineProfile CardPM
+Quote Post

snoj
RE: Play Music In Php
10 Dec, 2006 - 05:15 AM
Post #11

Fell off the face of the earth
Group Icon

Joined: 31 Mar, 2003
Posts: 3,325



Thanked: 9 times
Dream Kudos: 750
My Contributions
What he meant was that you would need to get the audio length of the file and store that information in your database.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 07:52PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month