fixed random playback

This commit is contained in:
oberon 2026-02-18 22:41:07 +01:00
parent 36d1a36549
commit c927d4d94b
3 changed files with 9 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View File

@ -12,6 +12,7 @@ from flask import Blueprint, jsonify, request, current_app
import app.state as state import app.state as state
from app.bluetooth.manager import MouldKing, advertiser, tracer from app.bluetooth.manager import MouldKing, advertiser, tracer
from app.utils.helpers import load_default_sounds, load_soundboard_configs, load_soundboard_config from app.utils.helpers import load_default_sounds, load_soundboard_configs, load_soundboard_config
from config import Config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
audio_lock = threading.Lock() audio_lock = threading.Lock()
@ -43,8 +44,13 @@ def _load_sound(file_path):
return snd return snd
def _play_sound_entry(sound_entry, channel_req=None, loop_req=0): def _play_sound_entry(sound_entry, channel_req=None, loop_req=0, sounds_dir=None):
sounds_dir = current_app.config['SOUNDS_DIR'] if sounds_dir is None:
try:
sounds_dir = current_app.config['SOUNDS_DIR']
except Exception:
sounds_dir = Config.SOUNDS_DIR
base_path = sound_entry.get('base_path') or sounds_dir base_path = sound_entry.get('base_path') or sounds_dir
file_path = os.path.join(base_path, sound_entry['file']) file_path = os.path.join(base_path, sound_entry['file'])
if not os.path.exists(file_path): if not os.path.exists(file_path):
@ -120,7 +126,7 @@ def _auto_random_tick():
# Play one random sound # Play one random sound
sound_entry, err = _pick_random_sound() sound_entry, err = _pick_random_sound()
if sound_entry: if sound_entry:
_play_sound_entry(sound_entry, sound_entry.get('channel'), sound_entry.get('loop')) _play_sound_entry(sound_entry, sound_entry.get('channel'), sound_entry.get('loop'), Config.SOUNDS_DIR)
# schedule next # schedule next
delay = rand_between(imin, imax) * 60 delay = rand_between(imin, imax) * 60
with auto_random_lock: with auto_random_lock: