tags:

views:

165

answers:

2

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.

{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>

i tried below codes but not working

changed {player.php}

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>

{player.php}

<?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 
echo $dom->saveXML();
?>
<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>
+2  A: 

I think the problem you're having is that multiple users are sharing the same .xml file.

You can easily get around this by one of these methods:

  1. Store the XML in a database (or directly in the session) and access it via the session ID.
  2. Use the session id as part of the filename

For the first one you'd change your embed to something like this:

musicplayer.swf?autostart=true&playlist=playlist.php

Then playlist.php would look like this:

<?php

session_start();
header('Content-type: text/xml');
print($_SESSION['xml']);

?>
Greg