I'm trying to write an interface to Win32::Sound into X-Chat, so Windows users can have a /sound command (and so some events can play sounds). Also, I'm trying to fork() this Win32::Sound::Play() off, so other events can occur without waiting for the sound to finish playing. However, during some events that call my sub, X-Chat crashes. I say "some events" because this doesn't occur everytime the sub is called, but it always occurs when the sub is called from a particular event. From that, I'm not sure if it's due to my code, fork() on Win32, or X-Chat itself. Here's the sub that I'm using to play wavs:
sub soundplay {
my($file) = shift;
if ($win32) { # Are we using Win32 X-Chat?
if ($fork) { # Does the user want to fork()?
my($pid) = fork();
if (!$pid) {
if (-e $file) { Win32::Sound::Play($file); }
elsif (-e "sounds/$file"){Win32::Sound::Play("sounds/$file");}
elsif (-e "data/$file") { Win32::Sound::Play("data/$file"); }
elsif (-e "dcc/$file") { Win32::Sound::Play("dcc/$file"); }
return 1;
}
return 1;
}
if (-e $file) { Win32::Sound::Play($file); }
elsif (-e "sounds/$file"){Win32::Sound::Play("sounds/$file");}
elsif (-e "data/$file") { Win32::Sound::Play("data/$file"); }
elsif (-e "dcc/$file") { Win32::Sound::Play("dcc/$file"); }
}
return 1;
}
And a calling event that causes a crash:
sub print_whois_chans_or_oper {
my(@line) = split(" ",$_[0]);
if ($_[0] eq " $line[0] is an IRC Operator") {
IRC::print(" [\002i\002rcop\002:\002 $line[0] is an IRCop\n");
soundplay("ohmy.wav") if $sounds; # Play if user wants sounds
}
else {
IRC::print(" [\002c\002hannels\002:\002 @line[1..$#line]\n");
}
return 1;
}
I understand that this is Perl, not X-Chat, discussion, but since I'm unsure if my code is at all sound, I thought I'd ask. Would love any input you folks have! Thanks in advance.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.