Re: Win32Lib: PlaySound/setVisible solution
- Posted by Dan Moyer <DanMoyer at PRODIGY.NET> Nov 03, 1999
- 513 views
Brian, Thanks for the code! Using it & David's suggestion for making playSound a function, I have unfortunately discovered that using playSound in async mode AND setting the SND_NOSTOP flag to allow a series of wave files to be played amount to the same thing as using playSound in sync mode. I took your demo solution & simplified it, from a "play list" orientation into just a "while" test loop of the SND_NOSTOP return (see below for snippet), so I could just feed PlaySound a series of wave files & the while loop would test to see if the preceding was finished & then when it was it would play the next & so forth till it did all of them. (This would be simpler to integrate into my application.) This worked just fine as far as making a sequence of wave files play in nominally async mode, no hiccups at all that I could force; BUT: now it operates essentially like SYNC mode did, in that the program is unresponsive to other events while that SEQUENCE of sounds is playing, which throws away that wonderful interruptibility I liked so much with ASYNC mode. I think the flag SND_NOSTOP means MORE than just that the playSound function returns false if the audio device is busy playing a sound, it also means DON'T STOP PLAYING UNTIL YOU'RE FINISHED (duh!), & that's exactly what SYNC mode does, I think. That "nostop" name had been bothering me in the back of my mind, now I see why. Bottom line seems to be that there's not much point in me using ASYNC mode, if in order to make multiple files play in sequence I end up with something indistinguishable from SYNC mode. Anyway, it was interesting, & I thank you for you effort. Your comments about your demo were crystal clear & really very helpful. Hope it wasn't a total waste of time for you. Here's snippets of what I made from your demo, using David's simpler prototype suggestion for changing xPlaySound procedure to a function (thanks David, I need examples I can cut'n'paste as much as I need explanations <sigh>). Dan Moyer -- MAKE NEW PLAYSOUND TO FUNCTION AS FUNCTION: global constant zPlaySound = linkFunc( winmm, "PlaySoundA", {C_INT, C_INT, C_INT}, C_INT ) -- taken from David's prototype suggestion -- PLAY A .WAV FILE if none is currently playing, or wait until finished if one is playing -- & then play it: procedure playsound(sequence wave) atom file file = allocate_string(wave) -- just loop here while/if previous wave playing, then play the new one: -- ("false" return means something is currently playing) while c_func(zPlaySound, {file, 0, or_all({SND_FILENAME, SND_ASYNC, SND_NOSTOP}) })= False do end while free(file) end procedure --SAY SOME THINGS: procedure DoTest_onClick () playsound("1.wav") playsound("2.wav") playsound("3.wav") playsound("4.wav") end procedure