Thanks! That makes sense, I'd have to install mpg123 to get that to work. But to have any hope of running my program on other machines, never mind other systems, I'd rather avoid that. If it's running an external process anyway, I might as well do it with afplay, right?

I'll show you what I have so far. It's a pretty primitive idea – the music script reads a line from a file, telling it which audio file to play, then waits for that to finish, and does it again.

for(1..5){ # should be an infinite loop $pid=fork(); if($pid==0){ my $m=getmusic(); if($m){exec 'afplay "'.$m.'"' or die} else{exec 'sleep 1'} } while (wait() != -1){ my $m=getmusic(); unless($m){ # somehow stop the music currently playing }else{ sleep 1; } } } sub getmusic{ open MFILE, "$path/music.txt" or die; my $m=<MFILE>; chomp $m; close MFILE; return $m; }

What I would need is: First, a way to call this from my main Perl program, and have it exit when that one does. Second, a way to get this script to kill the child process when it detects it's time to stop, in this example because the file is empty, as you see in the code.

Some of the links you posted also look interesting, although I don't understand much of them. I'll continue looking there too.


In reply to Re: Playing sounds by Chuma
in thread Playing sounds by Chuma

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.