Fijiannn Posted December 30, 2013 Share Posted December 30, 2013 Hi I have an .m3u playlist file on my server, it has links to different songs on my server. The .m3u playlist streams all the music. The thing I want the .m3u file to do is shuffle the music instead of going in the same order. I've been using this method to do it but it doesn't work. Any other ways or something wrong with my code? <?php $playlist = “/DONTFUCKWITHME/playlist.m3u"; if ($_SERVER['PATH_INFO'] == "/playlist.m3u") { # This a request for the actual playlist. playlist(); } else { # Fall through to end of script and display # the player HTML. } function playlist() { header("Content-type: audio/mpeg"); # Needed for PHP versions OLDER than 4.2.0 only. # If your host still has PHP older than 4.2.0, shame on them. # Find a better web host. srand(make_seed()); # Fetch our list of songs from a file. $songs = file($playlist); shuffle($songs); # Now output the URLs in random order. foreach ($songs as $song) { # Remove newline and any other leading and trailing # whitespace from URL of song. $song = trim($song); echo "$song\n"; } # Now exit before any HTML is produced. exit(0); } # Needed only for very old versions of PHP, # see srand call earlier. function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } ?> <html> <head> <title>MP3s Playing in Random Order</title> </head> <body> <h1 align="center">MP3s Playing in Random Order</h1> <embed src="/examples/randomsongs.php/playlist.m3u" width="0" height="0" autostart="true" type="audio/mpeg" loop="true"/> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/284970-shuffle-m3u-playlist/ Share on other sites More sharing options...
Firemankurt Posted December 30, 2013 Share Posted December 30, 2013 Replace: $playlist = “/DONTFUCKWITHME/playlist.m3u"; with: $playlist = '/DONTFUCKWITHME/playlist.m3u'; The first quote was a special character when I cut and pasted this code. Quote Link to comment https://forums.phpfreaks.com/topic/284970-shuffle-m3u-playlist/#findComment-1463263 Share on other sites More sharing options...
Firemankurt Posted December 30, 2013 Share Posted December 30, 2013 Add global $playlist; to the playlist function. function playlist() { global $playlist; scope of $playlist is your main problem. Quote Link to comment https://forums.phpfreaks.com/topic/284970-shuffle-m3u-playlist/#findComment-1463265 Share on other sites More sharing options...
Fijiannn Posted December 30, 2013 Author Share Posted December 30, 2013 Add global $playlist; to the playlist function. function playlist() { global $playlist; scope of $playlist is your main problem. None of this seem to work for me. Do you have your own method of shuffling an .m3u file through PHP? Quote Link to comment https://forums.phpfreaks.com/topic/284970-shuffle-m3u-playlist/#findComment-1463267 Share on other sites More sharing options...
Firemankurt Posted December 30, 2013 Share Posted December 30, 2013 Try change condition just for test by adding NOT: if ( ! $_SERVER['PATH_INFO'] == "/playlist.m3u") OR Add: echo $playlist; under : srand(make_seed()); and see what it outputs. Quote Link to comment https://forums.phpfreaks.com/topic/284970-shuffle-m3u-playlist/#findComment-1463271 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.