tags:

views:

159

answers:

3

Actually in my website www.musicking.in when the user selects songs one player window will open and that will access the corresponding selected songs xml playlist and the player will play those songs.

actually its working fine. but sometimes the problem is when so many users are accesiing the player not playing the songs selected, either its playing songs previously he selected or nothing.

please help me.

{my player code}

<?php
if(isset($_POST["song"])&& $_POST['song'] != "") 
    {
     $song = $_POST["song"];
    }
    else {$song=array();} 

$dom = new DOMDocument("1.0");
// display document in browser as plain text 
// for readability purposes

// create root element
$root = $dom->createElement("playlist");
$dom->appendChild($root);
$root->setAttribute('version', "1");
$root->setAttribute('xmlns', "http://xspf.org/ns/0/");
$rootnext = $dom->createElement("trackList");
$root->appendChild($rootnext);
foreach ($song as $counter) {
    $tokens = ",";
    $tokenized = strtok($counter, $tokens);
// create child element

$song = $dom->createElement("track");
$rootnext->appendChild($song);
$song1 = $dom->createElement("creator");
$song->appendChild($song1);
$text = $dom->createTextNode("www.musicking.in");
$song1->appendChild($text); 
$song1 = $dom->createElement("title");
$song->appendChild($song1);
// create text node
$text = $dom->createTextNode($tokenized);
$song1->appendChild($text); 
$tokenized = strtok($tokens);
$song1 = $dom->createElement("location");
$song->appendChild($song1);
$text = $dom->createTextNode($tokenized);
$song1->appendChild($text); 

}
// save 
$dom->save("playlist.xml");
?>
<object data="musicplayer.swf?autostart=true&playlist=playlist.xml" type="application/x-shockwave-flash" width="400" height="300"><param name="movie" value="musicplayer.swf?autostart=true&playlist=playlist.xml"/></object>




{sample playlist.xml}

<?xml version="1.0"?>
<playlist xmlns="http://xspf.org/ns/0/" version="1"><trackList><track><creator>www.musicking.in</creator><title>Ey Yavo </title><location>/telugusongs/prayanam/Ey Yavo.mp3</location></track><track><creator>www.musicking.in</creator><title>Meghamaa </title><location>/telugusongs/prayanam/Meghamaa.mp3</location></track><track><creator>www.musicking.in</creator><title>Nuvvu Entha </title><location>/telugusongs/prayanam/Nuvvu Entha.mp3</location></track></trackList></playlist>
+2  A: 

looks like you always use the file playlist.xml, and so if there are 10k visitors that single file is overwritten 10k times. Usually no problem but the internet is slow and so if one clicks ur site, the xml is generated and the swf is loaded which then uses the xml. There are delays in it and it might come to problems if one clicks and before his player loaded another one created an xml. I sugguest u use a variable filename (could be a random one) U might have to clean up the old files time after time

Flo
can u please help me in creating variable file names?i dont know how to do it.
musicking123
You could either go totally random but i do not really like that.One solution i would prefer is:$string = explode(" ",microtime());$string = $string[1] ."-". $string[0];then in $string is a string that contains the startpoint very detailed so i think it is not possible that two users interfere and you could relatively easy clean up old files via the timestamp
Flo
where i have to use this$string = explode(" ",microtime()); $string = $string[1] ."-". $string[0];
musicking123
Flo
its working but not perfect.......when i select another movie songs ,it showing previously selected songs
musicking123
The problem that occures because you have only one file is solved, this must have to do something with the part where you send the "song" variables to the php.Do some serious debugging, but it looks like you have no clue of php and stuff so i recommend asking someone to do that help you with that, asking for every single step here might take endless time
Flo
ya am poor at php. and no one is here to help me.i understood from above lines ismicrotime() function is giving current unix time stamp and we are eliminating delimiters by using explode functionso we r giving different file names each time.but its not working
musicking123
and one more thing its creating so many files in the directory..
musicking123
of course if does. As someone said in one of you other questions, using a database would probably be better than those xml stuff. If you use xml 1 see 3 ways to do it:a)As was beforeb)As is now (many files)c)one xml per song, but i think this might be problematic with playlistsYou could delete old files automatically as the timestamp is in the filename, you just need a script for that. Your error must come from another part of the process, use "echo" and "var_dump" to look at certain variables at different times to determine where the mistake is
Flo
A: 

Here's fast fix, but you really need to think this over.

Leave only this in that file:

if(isset($_POST["song"])&& $_POST['song'] != "") 
    {
        $song = $_POST["song"];
    }
    else {$song=array();} 
<object data="musicplayer.swf?autostart=true&playlist=playlist.php?song=<?=$song; ?>"      type="application/x-shockwave-flash" width="400" height="300"><param name="movie"   value="musicplayer.swf?autostart=true&playlist=playlist.php?song=<?=$song; ?>"/></object>

Then make playlist.php file with all the generation stuff:

if(isset($_GET["song"])&& $_GET['song'] != "") 
    {
        $song = $_GET["song"];
    }
    else {$song=array();}

....old generation code....
// Instead of saving it now, you just echo it. 
echo $dom->saveXML();

This is just really fast fix, I can't guarantee it will work since it depends how your music player reads files. But this is the way you want to go. You want to generate playlist file based on song parameter and echo it to browser.

Maiku Mori
ya itried it now.........but its not working
musicking123
just its showing player without playlist.
musicking123
please help me.................
musicking123
A: 

Somebody Please Help me...................................

musicking123
This is solved! The script writes to the XML what it gets and passes it to the player, if it doesnt play the right songs, there problem is somewhere else not in this sheet of php! Wont change if you "ask for help" for that another 100 times.
Flo