problem in playlist when we select the different songs

喜你入骨 提交于 2020-01-24 01:52:09

问题


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>

回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/1117923/problem-in-playlist-when-we-select-the-different-songs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!