Sorry to have to post two consecutive questions for other people to help me with, but I'm having a problem with winsound that I simply can't figure out. I've checked all the documentation I could, but there's no answer.

The problem is with SND_PURGE.

Stop playing all instances of the specified sound.

This is used in conjunction with PlaySound, which has the following entry:

PlaySound( sound, flags)

Call the underlying PlaySound() function from the Platform API. The sound parameter may be a filename, audio data as a string, or None. Its interpretation depends on the value of flags, which can be a bit-wise ORed combination of the constants described below. If the system indicates an error, RuntimeError is raised.

Also, SND_FILENAME is needed, I believe, since I'm playing from a file.

The sound parameter is the name of a WAV file. Do not use with SND_ALIAS.


Alright, so here's a problem. Put simply, SND_PURGE appears to do nothing.

Yes, absolutely nothing, no matter how I present it.

Take the following code. It shouldn't do anything, right?

from winsound import *

PlaySound("testSound.wav",SND_FILENAME) # Play testSound.wav
PlaySound("testSound.wav",SND_FILENAME|SND_PURGE) # Stop playing testSound.wav

Well, that doesn't work. Take out the SND_FILENAME from the fourth line? Still doesn't work. Am I using this wrong? And if so, can someone propose an alternative? Thanks in advance.

I don't think the SND_PURGE flag is meant to work the way you interpreted it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.