简体   繁体   中英

using winsound, plays error sound instead of chosen sound

I am fairly new to python. I am using winsound to play a swoosh sound.

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

with that. 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

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.

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)

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