#!/usr/bin/perl -w
use strict;
use warnings;

my $dir=shift @ARGV;
if(not $dir) {
	print "usage: $0 DIR\n";
	exit 1;
}

open(PIPE, "find '$dir' -type f |") or die $!;
my @l1=<PIPE>;
my @l2;
foreach(@l1) {
	chop;
	next unless /\.mp3$/ or /\.m4a$/;
	push(@l2, $_);
}
exit 0 if not @l2;

while(1){
	my $x=$l2[rand(@l2)];
	system("/usr/bin/mplayer",$x);
}
