mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-07-31 08:19:16 +02:00
wait
This commit is contained in:
+46
-51
@@ -324,50 +324,7 @@ def play_audio_with_crossfade(current_track_path, next_track_path=None, resume_s
|
|||||||
global current_process, next_process
|
global current_process, next_process
|
||||||
|
|
||||||
# Get duration of current track
|
# Get duration of current track
|
||||||
duration = get_audio_duration(current_track_path)
|
|
||||||
if not duration:
|
|
||||||
logger.warning(f"Could not get duration for {current_track_path}, playing without crossfade")
|
|
||||||
play_single_track(current_track_path, resume_seconds)
|
|
||||||
return
|
|
||||||
|
|
||||||
# Calculate when to start the next track (5 seconds before end)
|
|
||||||
crossfade_start_time = max(0, duration - CROSSFADE_DURATION - resume_seconds)
|
|
||||||
|
|
||||||
# Start current track with fade in
|
|
||||||
with process_lock:
|
|
||||||
current_process = create_audio_process(current_track_path, resume_seconds, fade_in=True, fade_out=True)
|
|
||||||
|
|
||||||
if next_track_path and crossfade_start_time > 0:
|
|
||||||
# Wait until it's time to start the crossfade
|
|
||||||
time.sleep(crossfade_start_time)
|
|
||||||
|
|
||||||
# Check if we need to stop due to control files
|
|
||||||
action = check_control_files()
|
|
||||||
if action in ["quit", "reload"]:
|
|
||||||
stop_all_processes()
|
|
||||||
return action
|
|
||||||
|
|
||||||
logger.info(f"Starting crossfade to: {os.path.basename(next_track_path)}")
|
|
||||||
with process_lock:
|
|
||||||
next_process = create_audio_process(next_track_path, fade_in=True, fade_out=True)
|
|
||||||
|
|
||||||
# Wait for crossfade to complete
|
|
||||||
time.sleep(CROSSFADE_DURATION * 1.5)
|
|
||||||
|
|
||||||
with process_lock:
|
|
||||||
if current_process and current_process.poll() is None:
|
|
||||||
try:
|
|
||||||
current_process.terminate()
|
|
||||||
current_process.wait(timeout=2)
|
|
||||||
except (subprocess.TimeoutExpired, ProcessLookupError):
|
|
||||||
pass
|
|
||||||
current_process = next_process
|
|
||||||
next_process = None
|
|
||||||
else:
|
|
||||||
# No crossfade, just wait for current track to finish
|
|
||||||
current_process.wait()
|
|
||||||
with process_lock:
|
|
||||||
current_process = None
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -404,6 +361,8 @@ def play_playlist(playlist_path, custom_playlist: bool=False, play_newest_first=
|
|||||||
random.shuffle(tracks)
|
random.shuffle(tracks)
|
||||||
|
|
||||||
for i, track in enumerate(tracks[start_index:], start_index):
|
for i, track in enumerate(tracks[start_index:], start_index):
|
||||||
|
if current_process: current_process.wait() # wait
|
||||||
|
|
||||||
current_modified_time = get_playlist_modification_time(playlist_path)
|
current_modified_time = get_playlist_modification_time(playlist_path)
|
||||||
if current_modified_time > last_modified_time:
|
if current_modified_time > last_modified_time:
|
||||||
logger.info(f"Playlist {playlist_path} has been modified, reloading...")
|
logger.info(f"Playlist {playlist_path} has been modified, reloading...")
|
||||||
@@ -463,22 +422,58 @@ def play_playlist(playlist_path, custom_playlist: bool=False, play_newest_first=
|
|||||||
if next_index < len(tracks):
|
if next_index < len(tracks):
|
||||||
next_track_path = os.path.abspath(os.path.expanduser(tracks[next_index]))
|
next_track_path = os.path.abspath(os.path.expanduser(tracks[next_index]))
|
||||||
|
|
||||||
# Play with crossfade
|
|
||||||
if i == start_index and resume_seconds > 0:
|
|
||||||
# For resumed tracks, use simpler playback
|
|
||||||
result = play_audio_with_crossfade(track_path, next_track_path, resume_seconds)
|
|
||||||
else:
|
|
||||||
result = play_audio_with_crossfade(track_path, next_track_path)
|
|
||||||
|
|
||||||
if result == "quit":
|
duration = get_audio_duration(track_path)
|
||||||
|
if not duration:
|
||||||
|
logger.warning(f"Could not get duration for {track_path}, playing without crossfade")
|
||||||
|
play_single_track(track_path, resume_seconds)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Calculate when to start the next track (5 seconds before end)
|
||||||
|
crossfade_start_time = max(0, duration - CROSSFADE_DURATION - resume_seconds)
|
||||||
|
|
||||||
|
# Start current track with fade in
|
||||||
|
with process_lock:
|
||||||
|
current_process = create_audio_process(track_path, resume_seconds, fade_in=True, fade_out=True)
|
||||||
|
|
||||||
|
if next_track_path and crossfade_start_time > 0:
|
||||||
|
# Wait until it's time to start the crossfade
|
||||||
|
time.sleep(crossfade_start_time)
|
||||||
|
|
||||||
|
# Check if we need to stop due to control files
|
||||||
|
action = check_control_files()
|
||||||
|
if action == "quit":
|
||||||
stop_all_processes()
|
stop_all_processes()
|
||||||
clear_state()
|
clear_state()
|
||||||
exit()
|
exit()
|
||||||
elif result == "reload":
|
elif action == "reload":
|
||||||
logger.info("Reload requested during playback...")
|
logger.info("Reload requested during playback...")
|
||||||
stop_all_processes()
|
stop_all_processes()
|
||||||
return "reload"
|
return "reload"
|
||||||
|
|
||||||
|
logger.info(f"Starting crossfade to: {os.path.basename(next_track_path)}")
|
||||||
|
with process_lock:
|
||||||
|
next_process = create_audio_process(next_track_path, fade_in=True, fade_out=True)
|
||||||
|
|
||||||
|
# Wait for crossfade to complete
|
||||||
|
time.sleep(CROSSFADE_DURATION * 1.5)
|
||||||
|
|
||||||
|
with process_lock:
|
||||||
|
if current_process and current_process.poll() is None:
|
||||||
|
try:
|
||||||
|
current_process.terminate()
|
||||||
|
current_process.wait(timeout=2)
|
||||||
|
except (subprocess.TimeoutExpired, ProcessLookupError):
|
||||||
|
pass
|
||||||
|
current_process = next_process
|
||||||
|
next_process = None
|
||||||
|
else:
|
||||||
|
# No crossfade, just wait for current track to finish
|
||||||
|
current_process.wait()
|
||||||
|
with process_lock:
|
||||||
|
current_process = None
|
||||||
|
|
||||||
|
|
||||||
# Clear state after track finishes
|
# Clear state after track finishes
|
||||||
clear_current_state()
|
clear_current_state()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user