user2919805
user2919805

Reputation: 125

Python - winsounds, how to play 2 sounds at the same time

I wrote this code, where I make 3 buttons and then when I hit 1 button, it plays sound A, I hit button 2, it plays sound B, etc.

from winsound import *
PlaySound("ooooOOooo.wav", SND_ASYNC)
PlaySound("WOOOWoooowooo", SND_ASYNC)

The buttons work and the sounds come out fine, but when I click 1 button and then second button right after that, it stops the first sound and plays the second.

How to make them play at the same time, so that the first still plays while the second one is added to play them togeter. I thought the mistake might be in flags, I tried a few combinations with the "|" operator but the problem still remains :(

Here are the resources: http://docs.python.org/2/library/winsound.html

I would prefer sticking to the python std library please :)

Thank you!

Upvotes: 1

Views: 2348

Answers (2)

user2919805
user2919805

Reputation: 125

Well, I thought using other modules is bad, but pygame works fine. Sounds are played well and importing this module into the cx_freezer is easy :)

Upvotes: 0

Serdalis
Serdalis

Reputation: 10489

According to the documentation

You need to do the following when using filenames:

PlaySound("ooooOOooo.wav", SND_ASYNC | SND_FILENAME)
PlaySound("WOOOWoooowooo.wav", SND_ASYNC | SND_FILENAME)

failing to do so is probably causing a None sound call to PlaySound which will cause:

If the sound parameter is None, any currently playing waveform sound is stopped. If the system indicates an error, RuntimeError is raised.

Upvotes: 1

Related Questions