Jump to content

Shuffle .M3U Playlist


Fijiannn

Recommended Posts

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>

 

Link to comment
https://forums.phpfreaks.com/topic/284970-shuffle-m3u-playlist/
Share on other sites

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.