#!/usr/bin/perl -w close STDOUT; @playlist = `cat ./playlist.txt`; $totalnum = scalar(@playlist); foreach $i (@playlist) { # a random number for the randomizer. $random = int(rand $totalnum); # use that random number to determine a file to play. $filename = $playlist[$random]; # format the file name so I can *USE* it. # the first regex escapes symbols for me. the second, spaces. $filename =~ s/(')|(&)|(\()|(\))/\\$+/g; $filename =~ s/\s/\\\ /g; # play the file, throw that process into the bg system("/usr/local/bin/ogg123 -d oss -q $filename &"); # write the PID and filename to a file # need this sleep in here to make shure the player starts before I try # to write the PID sleep 2; system("ps -U root --format pid --format fname| grep ogg123> ./player.pid"); open(PLAYING, ">./nowplaying.txt"); print PLAYING $filename; close PLAYING; # decriment the total number of files left to play. $totalnum--; # remove the filename from the list. splice @playlist, $random, 1; # get the information for the file that is playing. $playtime = `ogginfo $filename| grep length=`; # get the total playtime in secs for the file. $playtime =~ s/length=//; # pause for that many seconds, as to not play multiple files # simultaneously :) sleep $time; }