0

I'm building a simple space war game using python turtle. I want to play a laser sound every time I fire a missile, so I'm using the command: playsound("laser.mp3) the problem is that my game pause until the end of the sound. how do I make the sound play in the background? I know that for Mac system the command is os.system("afplay laser.mp3&"). What should be the command for Windows?

I try to play the mp3 file in the background of the game but the games keep pausing till the end of the mp3 file

1
  • Please share your current code as a minimal reproducible example. Rather than using an OS-specific subprocess call to a third party utility, I would use a Python sound library. Or use Pygame, since it's more suited for the use case of playing sounds in a game.
    – ggorlen
    Commented Jan 31 at 13:43

2 Answers 2

0

you can use cmd commands using os module:

os.system("start cmd /c {command here}")     # Launches in new command prompt, closes when done

in your case you can use something like:

import os
os.system("start cmd /C \"afplay laser.mp3\"")

0

Disclaimer:

"Nava" and more explicitly its async mode is a good solution for your case. Here is a simple use case:

from nava import play
sound_id = play("alarm.wav", async_mode=True)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.