'How to run pygame in the background?
I made a small pygame app that plays certain wav files in keypress using pygame.mixer All seem to work just fine except the fact that if you minimize the pygame window the program stops working until you open it again. Is there a way to solve this issue or an alternative way to implement sound playing in python?
This is my repository: https://github.com/Souvlaki42/HighPlayer
Solution 1:[1]
Try using pygame.mixer.music() but you'll need to convert all your wav files into mp3 files.
Solution 2:[2]
Just patch up all my mistakes your code from line 34 onwards should now be:
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
event2 = keyboard.read_event()
if event2.name == pygame.K_0:
stopSounds()
sound0.play()
if event2.name == pygame.K_1:
stopSounds()
sound1.play()
if event2.name == pygame.K_2:
stopSounds()
sound2.play()
if event2.name == pygame.K_3:
stopSounds()
sound3.play()
if event2.name == pygame.K_4:
stopSounds()
sound4.play()
if event2.name == pygame.K_5:
stopSounds()
sound5.play()
if event2.name == pygame.K_6:
stopSounds()
sound6.play()
if event2.name == pygame.K_7:
stopSounds()
sound7.play()
if event2.name == pygame.K_8:
stopSounds()
sound8.play()
if event2.name == pygame.K_9:
stopSounds()
sound9.play()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AzlanCoding |
| Solution 2 | AzlanCoding |
