alexander stevens
alexander stevens

Reputation: 13

using winsound, plays error sound instead of chosen sound

I am using winsound to play a swoosh sound:

winsound.PlaySound("D:\GamesImade\pythonpong\bounce.wav", winsound.SND_ASYNC)

When I run it with my IDE it works. But if I run the exe file by itself it doesn't work, it plays the windows error sound.

Upvotes: 1

Views: 3098

Answers (2)

ianharris
ianharris

Reputation: 11

I had a line of code that was supposed to run at a certain point and the code was accurately recognizing when the sound was supposed to be played, but it was only playing a windows error sound.

I changed the code from:

winsound.PlaySound("sound.wav", winsound.SND_ASYNC)

To:

winsound.PlaySound('C:/Users/username/OneDrive/Desktop/Project Folder/sound.wav', winsound.SND_ASYNC)

So, like the answer I switched the slashes around, but kept the SND_ASYNC and that runs in the program.

Upvotes: 1

chitown88
chitown88

Reputation: 28640

try changing the flag shown below and also the backslash to forward slash

winsound.PlaySound("D:\GamesImade\pythonpong\bounce.wav", winsound.SND_ASYNC)

to

winsound.PlaySound("D:/GamesImade/pythonpong/bounce.wav", winsound.SND_FILENAME)

Upvotes: 0

Related Questions