api.py: play_sound nutzt jetzt kein Thread und keine Busy-Wait-Schleife mehr.
This commit is contained in:
parent
723e25f05c
commit
434abad282
@ -220,17 +220,13 @@ def api_play_sound():
|
||||
logger.error(f"Sound-Datei nicht gefunden: {file_path}")
|
||||
return jsonify({"success": False, "message": "Sound-Datei nicht gefunden"}), 404
|
||||
|
||||
# Sound in separatem Thread abspielen (blockiert nicht)
|
||||
def play():
|
||||
try:
|
||||
pygame.mixer.music.load(file_path)
|
||||
pygame.mixer.music.play()
|
||||
while pygame.mixer.music.get_busy():
|
||||
time.sleep(0.1)
|
||||
except Exception as e:
|
||||
logger.error(f"Fehler beim Abspielen von {file_path}: {e}")
|
||||
|
||||
threading.Thread(target=play, daemon=True).start()
|
||||
# Abspielen (non-blocking, kein eigener Thread nötig)
|
||||
try:
|
||||
pygame.mixer.music.load(file_path)
|
||||
pygame.mixer.music.play()
|
||||
except Exception as e:
|
||||
logger.exception(f"Fehler beim Abspielen von {file_path}")
|
||||
return jsonify({"success": False, "message": str(e)}), 500
|
||||
|
||||
logger.info(f"Spiele Sound: {sound_entry['name']} ({sound_id})")
|
||||
return jsonify({"success": True, "message": f"Spiele: {sound_entry['name']}"})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user