Browse Source

don't freak out when the queue is totally empty, as can happen when the music path is invalid or empty

master
parent
commit
d4a1bfd6c3
  1. 18
      music-api.py

18
music-api.py

@ -668,10 +668,10 @@ def worker():
# Repeat_one: loop the first track # Repeat_one: loop the first track
if repeat_mode == "repeat_one": if repeat_mode == "repeat_one":
with queue_lock: with queue_lock:
current_track = queue[0] current_track = queue[0] if queue else None
path_current = os.path.join(MUSIC_DIR, current_track) path_current = os.path.join(MUSIC_DIR, current_track) if current_track else None
set_rds(f"RT {current_track}") set_rds(f"RT {current_track}")
played_ok = stream_file(path_current) played_ok = stream_file(path_current) if path_current else False
write_silence(0.25) write_silence(0.25)
with queue_lock: with queue_lock:
current_track = None current_track = None
@ -680,13 +680,13 @@ def worker():
# Normal / repeat_all # Normal / repeat_all
with queue_lock: with queue_lock:
current_track = queue[0] current_track = queue[0] if queue else None
path_current = os.path.join(MUSIC_DIR, current_track) path_current = os.path.join(MUSIC_DIR, current_track) if current_track else None
set_rds(f"RT {current_track}") set_rds(f"RT {current_track}")
print(f"[WORKER] Starting: {current_track} | queue={queue} | skip={skip_flag} stop={stop_flag}") print(f"[WORKER] Starting: {current_track} | queue={queue} | skip={skip_flag} stop={stop_flag}")
played_ok = stream_file(path_current) played_ok = stream_file(path_current) if path_current else False
# Snapshot flags under lock to avoid races # Snapshot flags under lock to avoid races
with queue_lock: with queue_lock:
@ -718,6 +718,12 @@ def worker():
print(f"[WORKER] Skip: popped {popped} | queue now {queue}") print(f"[WORKER] Skip: popped {popped} | queue now {queue}")
write_silence(0.25) write_silence(0.25)
continue continue
if not current_track:
# there was no song to play
write_silence(1)
time.sleep(1)
stop_flag = True
continue
# Real failure: log and drop the track to avoid infinite loop # Real failure: log and drop the track to avoid infinite loop
print("[WORKER] Track failed to play:", current_track) print("[WORKER] Track failed to play:", current_track)
with queue_lock: with queue_lock:

Loading…
Cancel
Save