How can I create a Randomized Playlist from an existing m3u

cantes903

New Member
I have a m3u playlist of 5 mp3's which plays fine on my web page. But of course it plays in the order they are on the list. I want to "somhow" make it radom so that a person may get a different song each time they visit the site. I have looked all over for quite a while now and can't find what I need or a tutorial on how to do it. ANY help would be greatly appreciated!

thanks in advanced-
Christy
 

thrive

New Member
I imagine you're using flash to play the files. I would recommend this:

+ Load each song into it's own movie (1,2,3,4,5).
+ Create a master movie that pulls in a song one at a time.
+ In the master movie in frame 1 set a cookie on the user's computer remembering which song was played last. It also looks to see if the cookie alreasy exists and if so it plays that cookie value + 1 (next song). If no cookie is detected it can grab a standard randomized number to figure which song it should play (for cookie diabled browsers).
 

cantes903

New Member
I'm probably gonna sound stupid since you assumed I'm using Flash but I wanted to use WMP to play the songs so the viewer could control volume and turn the song off if they wanted to. I have never used Flash, have no clue about it at all...lol..so I guess maybe I need to look into it?
 

thrive

New Member
It's a pain to be honest to use flash, but more people can use that with their browsers than windows media player. I run stats on some sites I manage, and out of roughly 4 million visits in a year's quearter, 89% of them can see flash. That's much much higher than wmp.

If you're using asp php etc you can just write the part that embeds your song with wmp in html. Name each son (1,2,3,4,5) and than in the part where it specifies the file name you just insert a random number there. I need to know what language you can use though.

BTW you can adjust volume, stop, next track in flash too.
 

cantes903

New Member
OK. Here is the closest thing I've come to so far, and it's using PHP (which I'm vaguely familiar with from school, but not even near proficient with.) What I've done is created a playlist.m3u with 5 mp3's on it. http://amigosleague.com/music/playlist.m3u

Playlist code as follows:

http://amigosleague.com/music/1.mp3
http://amigosleague.com/music/2.mp3
http://amigosleague.com/music/3.mp3
http://amigosleague.com/music/4.mp3
http://amigosleague.com/music/5.mp3


Then I created randomsongs.php and uploaded it to my server:
http://amigosleague.com/music/randomsongs.php

PHP coded as follows:

<?php
$playlist = "/www/a/m/amigosleague.com/htdocs/music/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="/music/randomsongs.php/playlist.m3u"
width="200"
height="100"
autostart="true"
type="audio/mpeg"
loop="true"/>
</body>
</html>



But when you try and access the randomsongs.php link it doesn't play. Since I don't know enough about php i used a step by step from this website: http://www.boutell.com/newfaq/creating/randomsongs.html.

OK, so NOW any suggestions??

BTW, I appreciate your helping me! I really want to get this cuz I hate giving up!
 

thrive

New Member
I only glanced over it but I see you haven't specified which song to play in your embed tag. Can you use asp? The code in asp is 1 line of code.
 
Top