|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How can I create a Randomized Playlist from an existing m3u
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 |
|
#2
|
||||
|
||||
|
What does the m3u look like?
Are you generating it, or simply posting a saved playlist? Does your webpage use a server-side language (such as PHP, ASP, Ruby, etc)?
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter! DevArticles Forum Moderator "The net is a waste of time, and that's exactly what's right about it." -- William Gibson |
|
#3
|
|||
|
|||
|
My playlist is just a listing of my songs in a notepad saved and uploaded as playlist.m3u. My server can use PHP too.
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. |
|
#4
|
||||
|
||||
|
I found something interesting.
Accessing http://amigosleague.com/music/randomsongs.php/playlist.m3u directly gave me a blank file. I was able to download the m3u directly using: http://amigosleague.com/music/playlist.m3u It then streamed in my media player... I assume you want it embedded in the page. I would look into why your script is giving out a blank file though. That's likely the cause. I also tried manually sending the HTTP requests for the m3u (while using your PHP script), and your server actually returned a 404... not sure if that's related |
|
#5
|
|||
|
|||
|
Ok, sounds like a good idea. The problems lies in I don't know why the script isn't working. lol I posted it in the post above your last if you have any ideas. Thanks a lot for your help!
|
![]() |
| Viewing: Dev Articles Community Forums > Web Design > Advanced Web Development > How can I create a Randomized Playlist from an existing m3u |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|