Added PLAYING, made PLAY more sophisticated, added some debugging.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@139 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/perl -w
|
#!/usr/bin/perl -w
|
||||||
#
|
#
|
||||||
# $Id: musicd,v 1.3 2001/03/22 02:59:13 mdb Exp $
|
# $Id: musicd,v 1.4 2001/06/05 16:40:53 mdb Exp $
|
||||||
#
|
#
|
||||||
# MP3 audio server. Manages playlists of mp3 files that live on a local
|
# MP3 audio server. Manages playlists of mp3 files that live on a local
|
||||||
# filesystem. The playlsits can be manipulated by connecting to the server
|
# filesystem. The playlsits can be manipulated by connecting to the server
|
||||||
@@ -10,6 +10,7 @@ use strict;
|
|||||||
use IO::Socket;
|
use IO::Socket;
|
||||||
use IO::Select;
|
use IO::Select;
|
||||||
use MPEG::MP3Play;
|
use MPEG::MP3Play;
|
||||||
|
use Data::Dumper;
|
||||||
|
|
||||||
# this is what's currently being played
|
# this is what's currently being played
|
||||||
my $playing;
|
my $playing;
|
||||||
@@ -106,15 +107,30 @@ sub handle_client
|
|||||||
foreach $path (@playlist) {
|
foreach $path (@playlist) {
|
||||||
print $cfh "$path\n";
|
print $cfh "$path\n";
|
||||||
}
|
}
|
||||||
return 1;
|
|
||||||
|
} elsif ($input =~ m/^PLAYING/) {
|
||||||
|
print $cfh "200 Currently playing: " .
|
||||||
|
(defined $playing ? $playing : "<none>") . "\n";
|
||||||
|
|
||||||
} elsif ($input =~ m/^STOP/) {
|
} elsif ($input =~ m/^STOP/) {
|
||||||
$mp3->stop();
|
$mp3->stop();
|
||||||
print $cfh "200 Music stopped.\n";
|
print $cfh "200 Music stopped.\n";
|
||||||
|
|
||||||
} elsif ($input =~ m/^PLAY/) {
|
} elsif ($input =~ m/^PLAY/) {
|
||||||
$mp3->play();
|
# if we've already queued up a song, play it
|
||||||
print $cfh "200 Music started.\n";
|
if (defined $playing) {
|
||||||
|
$mp3->play();
|
||||||
|
} else {
|
||||||
|
# otherwise queue one up to play
|
||||||
|
play_next_tune();
|
||||||
|
}
|
||||||
|
# and report back based on whether or not we successfully queued
|
||||||
|
# up a song for playing
|
||||||
|
if (defined $playing) {
|
||||||
|
print $cfh "200 Music started.\n";
|
||||||
|
} else {
|
||||||
|
print $cfh "501 Can't play: playlist empty.\n";
|
||||||
|
}
|
||||||
|
|
||||||
} elsif ($input =~ m/^PAUSE/) {
|
} elsif ($input =~ m/^PAUSE/) {
|
||||||
$mp3->pause();
|
$mp3->pause();
|
||||||
@@ -164,8 +180,29 @@ package MPEG::MP3Play;
|
|||||||
sub msg_notify_player_state
|
sub msg_notify_player_state
|
||||||
{
|
{
|
||||||
my ($mp3, $msg) = @_;
|
my ($mp3, $msg) = @_;
|
||||||
|
print "state: " . Dumper($msg) . "\n";
|
||||||
# play the next tune if we hit the end of this one
|
# play the next tune if we hit the end of this one
|
||||||
main::play_next_tune()
|
if ($msg->{state} == &XA_PLAYER_STATE_EOF) {
|
||||||
if ($msg->{state} == &XA_PLAYER_STATE_EOF);
|
main::play_next_tune();
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub msg_notify_error
|
||||||
|
{
|
||||||
|
my ($mp3, $msg) = @_;
|
||||||
|
print "error: " . Dumper($msg) . "\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub msg_notify_debug
|
||||||
|
{
|
||||||
|
my ($mp3, $msg) = @_;
|
||||||
|
if ($msg->{code} == &XA_ERROR_NO_SUCH_FILE) {
|
||||||
|
print "unable to load: $playing\n";
|
||||||
|
} else {
|
||||||
|
print "debug: " . Dumper($msg) . "\n";
|
||||||
|
}
|
||||||
|
print "nsf: " . &XA_ERROR_NO_SUCH_FILE . "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user