Stop audio
This commit is contained in:
parent
928ca39c8c
commit
d4bc8d747b
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user