Randomize links in a playlist to play in WMP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DrossZro
Forum Newbie
Posts: 3
Joined: Mon Nov 27, 2006 7:11 pm

Randomize links in a playlist to play in WMP

Post by DrossZro »

Hey everyone, new here, but could really use your help

Basically i have a php doc that opens a file (playlist.m3u) and mixes up the links to the audio, and then plays them in windows media player in the same browser page. Well thats what i want to do anyway. Heres what i got so far, most of it from a tutorial i found.

Code: Select all

<?php
 $playlist = "/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>

<OBJECT ID="MediaPlayer1" CLASSID="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab# Version=5,1,52,701" STANDBY="Loading Microsoft Windows® Media Player components..." TYPE="application/x-oleobject" width="280" height="46">
<param name="fileName" value="playlist.m3u">
<param name="animationatStart" value="true">
<param name="transparentatStart" value="true">
<param name="autoStart" value="true">
<param name="showControls" value="true">
<param name="Volume" value="-300">
<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="playlist.m3u" name="MediaPlayer1" width=280 height=46 autostart=1 showcontrols=1 volume=-300>
</OBJECT>
</body>
</html>


i got it from http://www.boutell.com/newfaq/creating/randomsongs.html




k, i know my playlist is set up right, i think the only part i really need to worry about is what gets linked to what. The only things i think i need to fix is the first /playlist.m3u and the two located in the embeded WMP code. The playlist is located at http://ryanvollmer.com/music/playlist.m3u and the php file is at http://ryanvollmer.com/music/randomsongs.php. They both are located in the server directory of /public_html/music/. The player loads but wont play anything. I think i included everything i can think of, thanks for lookin...

ryan
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Post by DaveTheAve »

So i take it the URI of http://ryanvollmer.com/music/playlist.m3u gets redirected (hopefully via .htaccess) to http://ryanvollmer.com/music/randomsongs.php with the correct variables and randomsongs.php handles the request and as I can see sends out the right header,

If this is wrong please acknowledge that fact now. This post was meant to clarify your problem. Thank you.
DrossZro
Forum Newbie
Posts: 3
Joined: Mon Nov 27, 2006 7:11 pm

Post by DrossZro »

From what i got, im suppose to just open the randomsongs.php file and that handles everything. First randomsongs opens up the playlist and rearranges the links in the playlist before anything else, then starts the html to open the player and the player plays the playlist....does that answer your question? Sorry, this took awhile for me to figure out and im still learning. Im not sure what .htaccess is, but it sounds like you got the idea. feel free to ask anything else.'
thanks

ryan
DrossZro
Forum Newbie
Posts: 3
Joined: Mon Nov 27, 2006 7:11 pm

Post by DrossZro »

if you know of any other way to open a m3u and rearange the links feel free to suggest that too.
Post Reply