Reputation: 1
Currently working on a stupid/crazy project: Making an 8-Bit RPG top down game using only Turtle.
One of the problems I'm having is with background music. I use the winsound module and make sure all my sounds use the SND_ASYNC flag so that I can cut it off before it's done if I need to.
I want to know if there's a way to loop the sound while still keeping it async without it stopping the previous sound before it's done, but still being able to cut off the sound and stop the loop if I need to.
I've tried a while loop, but since it stops the previous sound it just kept looping the first second.
I thought about combining the SND_NOWAIT flag with the SND_ASYNC flag, but I don't know how I would do that.
And then I tried using the time module and doing time.sleep(120
to make it wait for the duration of the song (2 minutes) before playing it again, but that just stops the sound because it's async.
Upvotes: 0
Views: 26
Reputation: 36763
I thought about combining the SND_NOWAIT flag with the SND_ASYNC flag, but I don't know how I would do that.
From windsound.PlaySound(sound, flags)
docs
Its interpretation depends on the value of flags, which can be a bitwise ORed combination of the constants described below.
which means you should use bitwise OR (|
) if you wish to apply more than one flag. Thus playing song.wav
in loop might be done following way
import winsound
winsound.PlaySound("song.wav", winsound.SND_FILENAME | winsound.SND_ASYNC | winsound.SND_LOOP)
I do not have Windows machine at hand, so please test if it does what you wants.
Upvotes: 0