Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Win32::Sound with text

by sulfericacid (Deacon)
on Oct 14, 2005 at 23:18 UTC ( [id://500400]=perlquestion: print w/replies, xml ) Need Help??

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

After reading a node recently on playing sounds through the command prompt, I decided I'd give it a try with Win32::Sound.

It works great with Wav playback but I have run into a problem. While running this on Windows XP's command prompt, it'll load the song and play it BUT it will not allow anything else to continue until the song is done. This is to say, I want to print stuff to screen during the wav playback but it's just not pushing through.

Anyone have suggestions on how to get around this?

UPDATE: The solution is adding SND_ASYNC to the file open. Win32::Sound::Play($song, SND_ASYNC); does the trick.

#!/usr/bin/perl use warnings; use strict; use Win32::Sound; my $song = "one.wav"; Win32::Sound::Play($song); my $num = 0; for (1 .. 35) { $num++; print "$num\n"; sleep(1); if ($num == 30) { Win32::Sound::Stop(); } }


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
Re: Win32::Sound with text
by GrandFather (Saint) on Oct 15, 2005 at 01:43 UTC

    Try Win32::Sound::Play ($song, SND_ASYNC);


    Perl is Huffman encoded by design.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Win32::Sound with text
by Skeeve (Parson) on Oct 14, 2005 at 23:34 UTC

    Maybe you should fork a new thread or create a process to play the sound?

    I have almost no experience with perl on windows. Maybe the thread win32 forking and threads gives you some hints how to start another process?


    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://500400]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-24 19:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found