I am trying out Python's pygame
module to test its ability to play sound from a file. However, I am building a larger program where I can play this sound in a separate thread while the regular program continues to execute. Below I have posted a simple example of what I plan to do. Here is my code:
import pygame
import time
from threading import Thread
def play_alarm2():
pygame.mixer.init()
sound = pygame.mixer.Sound("/home/souvik/Downloads/alarm_beep.wav")
sound.play()
time.sleep(4)
alert = False
count = 0
while count <= 10:
print("Alive!")
if count == 5:
print("Dead!")
t = Thread(target=play_alarm2)
t.daemon = True
t.start()
count += 1
Here as soon as the count hits 5, it should make a sound. But unfortunately, I don't hear any sound which makes me thinking if the thread actually starts. What could I be doing wrong?