...

View Full Version : How to make random play?



NautTboy
09-28-2011, 03:56 PM
Here is the code I have that will play in both IE and FF:

<embed name="playlist"
src="/MUSIC/playlist.m3u"
type="application/x-mplayer2"
width="300"
height="90"
loop="true"
hidden="false"
autostart="true"
shuffle="true" <--adding this didn't work
</embed>

How can I make it play random instead of the first song listed in the playlist?

NautTboy
09-28-2011, 04:33 PM
found this. He said needed to make php file. I'd tried but didn't work.

<?php
$playlist = "/home/sites/myname/www.example.com/examples/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>


Not sure if i can post the link on here, i'll need to go back and read the "read me before postin"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum