简体   繁体   中英

How to start/stop wav-sounds under C++ Windows 7

I tried hard to find a solution for the follwing requirement under C++/Visual Studio:

It's simple: For purpose of alarming I have to play a number of wav sounds from files sequentially in an endless loop, each separated by a short delay:

sound-1 ...sound-2 ... sound-n ... sound-1 ... sound-2 ...

At any time it should be possible to cancel this sequence of sounds.

I tried to play around with PlaySound() , but the problem is, that I cannot stop the sounds properly once they are running.

https://msdn.microsoft.com/en-us/library/Dd743680(v=VS.85).aspx

When a sound is played asynchronously by flag, it can be stopped by specifying a NULL for parameter 1, but then I can't know when sound-1 is finished before sound-2 is started. In fact, starting sound-2 would interrupt sound-1.

In synchroneous mode however, interruption of a sound is not possible.

To be able to cancel sounds I tried to put PlaySound into a Poco::Thread , but how to cancel a thread? It is not foreseen to cancel a thread...Using Poco::Task instaed gives an unhandled exception at 0x01002d62 ... upon cancelling, so it doesn't work either.

What would be the preferred solution for that? Is there a better solution?

Thanks!

They're all WAV files, you know how long they last. When you start playing sound1 , store the time it will end. There's no need to guess.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM