Gary wrote: > Several docs I have warn of doom and destruction if > thou dost unlock a handle to an audio resource while > it's still playing...I can certainly attest to > that... > > ..but how am I to test and ensure the wave is > finished playing before I operate on the handle? On > this the scriptures are silent. :( > > I'm using "SndPlayResource" with the "sndFlagAsync" > flag btw.
I pondered that question a while back, and the conclusion I came to is that there IS no way to find out when the sample has finished playing, and sndFlagAsync is fundamentally broken. You could try using a timer to estimate when the sample is finished, but that is messy (especially when you consider the system going to sleep while the sound is going!) and not really guaranteed to work 100% of the time. Which just means you've moved into "well, it *probably* won't crash" territory. However, it seems like there's a way around it. You can play sampled sound by creating a stream (SndStreamCreate() or, preferably, SndStreamCreateExtended()) and having it call a callback that you supply in order to fill a buffer with sample data. Then the callback can call SndStreamStop() to stop the stream and unlock the resource. As I read the documentation, at this point the sound could still be playing, but since the buffers are allocated by the sound manager and not the application, that's its problem. (But you probably want to keep track of whether a sound is playing with some kind of flag and, if so, call SndStreamStop() on it before you app closes, in case the sound is still playing when your app is trying to exit.) Oh yes, the down side of that is that you have to either put raw PCM data in your resources (which isn't sooo bad) or write code to parse a WAV if you want to play WAV resources. So you can't use this to write a drop-in replacement for SndPlayResource(). By the way, if there IS a correct way to use SndPlayResource with sndFlagAsync, I'd love to know about it. - Logan -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
