fixed random playback
This commit is contained in:
parent
36d1a36549
commit
c927d4d94b
BIN
app/__pycache__/__init__.cpython-314.pyc
Normal file
BIN
app/__pycache__/__init__.cpython-314.pyc
Normal file
Binary file not shown.
BIN
app/routes/__pycache__/api.cpython-314.pyc
Normal file
BIN
app/routes/__pycache__/api.cpython-314.pyc
Normal file
Binary file not shown.
@ -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:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user