Stop audio
This commit is contained in:
parent
928ca39c8c
commit
d4bc8d747b
@ -32,14 +32,29 @@ import sys
|
||||
import pygame
|
||||
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):
|
||||
global PLAY_SOUND
|
||||
PLAY_SOUND = True
|
||||
pygame.mixer.init()
|
||||
pygame.mixer.music.load(filename)
|
||||
time_start = time.time()
|
||||
pygame.mixer.music.play()
|
||||
|
||||
while pygame.mixer.music.get_busy():
|
||||
if not PLAY_SOUND:
|
||||
pygame.mixer.music.stop()
|
||||
break
|
||||
duration = time.time() - time_start
|
||||
yield duration
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user