Page 1 of 1

A work-around for random mp3 playlist

Posted: 07 Dec 2006, 15:10
by joey
You need to follow these steps to get it working:
1. drop rename.php in your gallery folder
2. add this line in your index.php:
Code
require_once('rename.php');
Contents of rename.php:
Code
<?php

// Rename files with random names

$musicdir = @opendir("mp3"); 
$cc = 0;
while($filename = readdir($musicdir)) {
	if (ereg("\.mp3|\.MP3", $filename)) 
	{ 
		$namearray[$cc] = "mp3/". $filename; $cc++; 
	}
}

for ($i=0; $i<count($namearray); $i++) {
	$extension = strstr($namearray[$i], ".");
	$rndnm = "mp3/". rand(10,1000) . $extension;
	@rename($namearray[$i], $rndnm);
}

?>
Karl or anyone else: If you think this will introduce bugs or have better solutions, please advise.

Thanks!

Posted: 07 Dec 2006, 17:07
by joey
While I'm at it, how about randomizing the monotonous slidshow that starts iterating through the same images?
Code
<?php

// Rename files with random names

$musicdir = @opendir("mp3"); 
	$cc = 0;
	while($filename = readdir($musicdir)) {
		if (ereg("\.mp3|\.MP3|\.jpg|\.JPG", $filename)) { 	
			$namearray[$cc] = "mp3/". $filename; $cc++; 
		}
	}

for ($i=0; $i<count($namearray); $i++) {
	$extension = strstr($namearray[$i], ".");
	$rndnm = "mp3/". rand(10,1000) . $extension;
	@rename($namearray[$i], $rndnm);
}

?>

Posted: 08 Dec 2006, 14:15
by Nick
Hmm, interesting approach, but here is alternative suggestion - for getting mp3 tracks in random order every time just change in readfolder.php
Code
Line 25:
sort ($files);

to:
if ($ext=='mp3') shuffle($files); else sort ($files);

Posted: 09 Dec 2006, 10:13
by globetrotter
pain wrote:Hmm, interesting approach, but here is alternative suggestion - for getting mp3 tracks in random order every time just change in readfolder.php
Code
Line 25:
sort ($files);

to:
if ($ext=='mp3') shuffle($files); else sort ($files);
It works great!

In Firefox 2 you have an other song each page-refresh, and in IE6 every time you open the gallery in a new window.

Thanks Nick

Posted: 10 Dec 2006, 11:31
by Hanky
yes, it works really great - thanks to pain :P