Stop audio

This commit is contained in:
retoor 2025-01-19 02:30:39 +01:00
parent 928ca39c8c
commit d4bc8d747b

View File

@ -32,17 +32,32 @@ import sys
import pygame import pygame
import time import time
PLAY_SOUND = True
def stop_audio():
global PLAY_SOUND
PLAY_SOUND = False
async def stop_audio_async():
global PLAY_SOUND
PLAY_SOUND = False
async def play_audio_async(filename): async def play_audio_async(filename):
global PLAY_SOUND
PLAY_SOUND = True
pygame.mixer.init() pygame.mixer.init()
pygame.mixer.music.load(filename) pygame.mixer.music.load(filename)
time_start = time.time() time_start = time.time()
pygame.mixer.music.play() pygame.mixer.music.play()
while pygame.mixer.music.get_busy(): while pygame.mixer.music.get_busy():
if not PLAY_SOUND:
pygame.mixer.music.stop()
break
duration = time.time() - time_start duration = time.time() - time_start
yield duration yield duration
def play_audio(filename): def play_audio(filename):
pygame.mixer.init() pygame.mixer.init()