Topic: Howto: Poor man's iPod Shuffle for the Chumby
1. Save the following to a file on your USB flash drive (i.e. playmp3s.pl):
#!/usr/bin/perl
main();
sub main {
@lines = split(/\n/,`mp3.x mp3://usb`);
fisher_yates_shuffle(\@lines);
foreach $line (@lines) {
if($line =~ '>mp3:\/\/(.*)<') {
`btplay /mnt/$1`;
}
}
}
sub fisher_yates_shuffle {
my $array = shift;
my $i;
for ($i = @$array; --$i; ) {
my $j = int rand ($i+1);
next if $i == $j;
@$array[$i,$j] = @$array[$j,$i];
}
}
2. Make a debugchumby file (no extension) on the flash drive with the following:
#!/bin/sh
/mnt/usb/playmp3s.pl &
3. Put a bunch of mp3s on the flash drive and boot with the flash drive plugged in.
It will play them in a different order on each boot.
(Thanks to Duane for everything but the shuffle code. Shuffle code from http://community.livejournal.com/perl/101830.html)