[MPlayer-users] Slave Mode from Perl

Mark Zealey mark at zealos.org
Tue Jul 1 18:59:35 CEST 2003


I wrote my own script to do this, havnt bothered to look at in a while but it
uses mplayer as a backend to play music. i've put it up at:
http://pkl.net/~mark/play

if you want to have a lookie at how it handles all that stuff.

On Tue, Jul 01, 2003 at 12:11:17AM -0400, Russell Altieri wrote:

> [Automatic answer: RTFM (read DOCS, FAQ), also read DOCS/bugreports.html]
> FYI,
> 	I have been wanting to use slave mode and use a Perl/Tk GUI for a
> mobile car MP3 player I'm working on.  The problem is opening up a pipe
> to mplayer,  sending commands to it at anytime, and getting back the
> time in file with get_percent_pos.  Well anyway, here is a little
> example script which will use open2 and Term::Readkey's Readline to do a
> bidirectional pipe.  I called my script slave-mode.pl
> 
> Russ
> 
> begin slave-mode.pl -----------
> #!/usr/bin/perl -w
> # Perl Modules
> 
> use IPC::Open2;
> use IO::Handle;
> use Term::ReadKey;
> use sigtrap;
> my $song_playing=1;
> my $file = shift(@ARGV);
> if ($file) {
> 	print $file , "\n";
> 	$SIG{'PIPE'} = 'handler';
> 	open2(\*R, \*W, "mplayer -slave -quiet $file");
> 	clearbuffer();
> 	ReadMode "raw" , *R ;
> 	update_time();
> 	
> } else { print "usage\n";
> 	 print "\.\\slave\-mode\.pl mp3file.mp3\n";
> }
> 
> sub handler {
>     $song_playing = 0;
>     close W;
>     close R;
> }
> sub update_time {
> 	my $time=get_time();
> 	while ($time && $song_playing) {
> 		select(undef,undef,undef,1.0); # good way to pause 
> 		$time=get_time(); 
> 	}
> 	print "done\n";
> }
> sub get_time {
> 	print W "get_percent_pos\n" ;
> 	if ($song_playing) {
> 		W->autoflush() ;
> 		my $line=ReadLine -1 , *R ;
> 		R->autoflush() ;
> 		print "$line";
> 		if ($line) {
> 			my @parse = split (/A:/ , $line);
> 			if ($parse[1]) {
> 				@parse = split (/ / , @parse[1] ) ;
> 				my $count=0;
> 				my $string = @parse[$count];
> 				until ($string) {
> 					$string = @parse[$count];
> 					$count+=1;
> 					if ($count >= 10) {$string="*";}
> 				}
> 				print "\n--" , @parse[$count-1] , "\n";
> 			}
> 		
> 		}
> 		clearbuffer();
> 		print "buffer Cleared\n";
> 	}
> }
> sub clearbuffer {
> 	my $line=ReadLine -1 , *R ;
> 	
> 	while ($line) {
> 		$line=ReadLine -1 , *R  ;
> 	}
> 	R->autoflush() ;
> }
> 
> _______________________________________________
> RTFM!!!  http://www.MPlayerHQ.hu/DOCS
> Search:  http://www.MPlayerHQ.hu/cgi-bin/htsearch
> http://mplayerhq.hu/mailman/listinfo/mplayer-users

-- 

Mark Zealey (aka JALH on irc.oftc.net: #zealos and many more)
mark at zealos.org; mark at itsolve.co.uk

UL++++>$ G!>(GCM/GCS/GS/GM) dpu? s:-@ a18! C++++>$ P++++>+++++$ L+++>+++++$
!E---? W+++>$ !w--- r++ !t---?@ !X---?  !R- !tv b+ G+++ e>+++++ !h++* r!-- y



More information about the MPlayer-users mailing list