halfcountplus has asked for the wisdom of the Perl Monks concerning the following question:

i want to use sox & mpg123 in "browsing" soundfiles in a tk app, but i do not simply want system "play file.wav" since i would like to give me the user the option of stopping the command in media res.

Is there a simple clever way to do this via some module or do i have to go about getting the pid of the process and kill it circuitously?

Replies are listed 'Best First'.
Re: pre-empt launched process
by Anonymous Monk on Mar 06, 2008 at 07:16 UTC
Re: pre-empt launched process
by zentara (Cardinal) on Mar 06, 2008 at 15:51 UTC
    You can open sox with IPC, but the syntax can be tricky, see I need some help with open2 You need to get the | and - syntax right. The syntax for sox can be tricky, so search google and groups.google for "perl sox".

    You need to read all the docs that come with sox and mpg123, to find the recommended syntax for interactive playing. To be honest, mplayer is probably easier to work with interactively. See Perl/Tk front-end to mplayer As far as mpg123 goes, this should show a trick

    #!/usr/bin/perl use warnings; use strict; use Tk; # read README.remote in mpg123 sources # only works after mainwindow is closed ???? $|++; my $pid = open(FH,"| mpg123 -@ - "); print "$pid\n"; my $mw = new MainWindow; my $startbut = $mw->Button(-text =>'Start Play', -command => sub{ syswrite(FH, "1bb.mp3\n") ; })->pack; MainLoop;

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum