
204
Scheduling and Buffering
Part II: Home Entertainment
sub clean {
system "find $frankdir/*.$audioext -mtime +$_[0] -exec rm -rf {}
\\;"
}
sub jump {
# Calculate new position in audio file relative to current
my $remote=Xmms::Remote->new;
my $previoustime = $remote->get_output_time;
my $absolutetime = $previoustime+(1000*$_[0]);
# Check the current length of the audio file. If we're jumping
# beyond the end, request XMMS jump only to the end (minus the
buffer)
my $active = `cat $frankdir/active\n`;
chomp $active;
# Try to check the length of the file. If it's not an OGG file,
that's okay.
my $oggfile = Ogg::Vorbis::Header->new($active);
if ( $oggfile )
{
my $length = ($oggfile->info('length') - $buffer) * 1000;
if ( $absolutetime > $length ) { $absolutetime = $length; }
}
$remote->jump_to_time($absolutetime);
sleep 1;
# Ask XMMS for the current time to verify that the jump
# was successful. If it wasn't, stop and restart XMMS
# and try again.
my $actualtime = $remote->get_output_time;
if (($actualtime < ($absolutetime-1000)) || ($actualtime >
($absolutetime+1000)))
{
# We have to stop and restart XMMS, which causes XMMS to
# play a bit of the beginning of the file. To prevent the user
# from hearing this, temporarily mute XMMS.
my $currentvolume = $remote->get_volume;
$remote->set_volume(0) if ($currentvolume > 0);
$remote->stop;
$remote->play;
sleep 1;
$remote->jump_to_time($absolutetime); ...