Fix MPV pause state bug when loading new files
All checks were successful
Build and Release / build-and-release (push) Successful in 52s
All checks were successful
Build and Release / build-and-release (push) Successful in 52s
When MPV is paused and a new file is loaded via loadfile command, MPV loads the file but remains in a paused state. This caused the UI to show "Playing" while no audio was actually playing. Fix: Explicitly call resume() after every play() call to ensure MPV unpauses when loading new files. This applies to: - Playing new folder/file selections - Playing from playlist - Auto-play next/previous track - Removing currently playing track from playlist Fixes bug where after pause, playing another folder would show "Playing" status but remain silent at 00:00.
This commit is contained in:
parent
f1412b4f8c
commit
b59d1aed65
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-player"
|
||||
version = "0.1.19"
|
||||
version = "0.1.20"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
12
src/main.rs
12
src/main.rs
@ -96,6 +96,8 @@ fn action_play_selection(state: &mut AppState, player: &mut player::Player) -> R
|
||||
state.play_selection();
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
// Explicitly resume playback in case MPV was paused
|
||||
player.resume()?;
|
||||
state.player_state = PlayerState::Playing;
|
||||
player.update_metadata();
|
||||
tracing::info!("Playing: {:?} (playlist: {} tracks)", path, state.playlist.len());
|
||||
@ -126,6 +128,7 @@ fn action_toggle_play_pause(state: &mut AppState, player: &mut player::Player) -
|
||||
state.player_state = PlayerState::Playing;
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
player.resume()?;
|
||||
player.update_metadata();
|
||||
tracing::info!("Restarting playback: {:?}", path);
|
||||
}
|
||||
@ -156,6 +159,8 @@ fn action_remove_from_playlist(state: &mut AppState, player: &mut player::Player
|
||||
state.current_file = Some(state.playlist[state.playlist_index].clone());
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
// Explicitly resume playback in case MPV was paused
|
||||
player.resume()?;
|
||||
player.update_metadata();
|
||||
}
|
||||
}
|
||||
@ -171,6 +176,7 @@ fn action_play_from_playlist(state: &mut AppState, player: &mut player::Player,
|
||||
PlayerState::Playing => {
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
player.resume()?;
|
||||
player.update_metadata();
|
||||
tracing::info!("Jumped to track: {:?}", path);
|
||||
}
|
||||
@ -187,6 +193,7 @@ fn action_play_from_playlist(state: &mut AppState, player: &mut player::Player,
|
||||
state.player_state = PlayerState::Playing;
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
player.resume()?;
|
||||
player.update_metadata();
|
||||
tracing::info!("Started playing track: {:?}", path);
|
||||
}
|
||||
@ -196,6 +203,8 @@ fn action_play_from_playlist(state: &mut AppState, player: &mut player::Player,
|
||||
state.player_state = PlayerState::Playing;
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
// Explicitly resume playback in case MPV was paused
|
||||
player.resume()?;
|
||||
player.update_metadata();
|
||||
tracing::info!("Playing from playlist: {:?}", path);
|
||||
}
|
||||
@ -306,6 +315,7 @@ async fn run_app<B: ratatui::backend::Backend>(
|
||||
last_position = 0.0;
|
||||
|
||||
player.play(path)?;
|
||||
player.resume()?;
|
||||
}
|
||||
// Update metadata immediately when track changes
|
||||
player.update_metadata();
|
||||
@ -519,6 +529,7 @@ async fn handle_key_event<B: ratatui::backend::Backend>(terminal: &mut Terminal<
|
||||
// Keep playing
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
player.resume()?;
|
||||
player.update_metadata(); // Update metadata immediately
|
||||
tracing::info!("Next track: {:?}", path);
|
||||
}
|
||||
@ -557,6 +568,7 @@ async fn handle_key_event<B: ratatui::backend::Backend>(terminal: &mut Terminal<
|
||||
// Keep playing
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
player.resume()?;
|
||||
player.update_metadata(); // Update metadata immediately
|
||||
tracing::info!("Previous track: {:?}", path);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user