fix(mpris): update progress during playback polling

- Update MPRIS position every time get_playback_state is polled (~500ms)
- Update MPRIS position when seeking
- Add Default derive to PlaybackState for error fallback
- System media controls now show accurate playback progress
This commit is contained in:
vicrodh committed 2026-01-09 12:12:26 -06:00
1 parent 0075b5fc60
commit 8f4a47b2d8
2 files changed
+21 -4

No files matched your search

+20 -3
View File
@@ -231,13 +231,30 @@ pub fn set_volume(volume: f32, state: State<'_, AppState>) -> Result<(), String>
#[tauri::command] #[tauri::command]
pub fn seek(position: u64, state: State<'_, AppState>) -> Result<(), String> { pub fn seek(position: u64, state: State<'_, AppState>) -> Result<(), String> {
log::info!("Command: seek {}", position); log::info!("Command: seek {}", position);
state.player.seek(position) let result = state.player.seek(position);
// Update MPRIS with new position
let playback_state = state.player.get_state().unwrap_or_default();
state.media_controls.set_playback_with_progress(
playback_state.is_playing,
position,
);
result
} }
/// Get current playback state /// Get current playback state (also updates MPRIS progress)
#[tauri::command] #[tauri::command]
pub fn get_playback_state(state: State<'_, AppState>) -> Result<PlaybackState, String> { pub fn get_playback_state(state: State<'_, AppState>) -> Result<PlaybackState, String> {
state.player.get_state() let playback_state = state.player.get_state()?;
// Update MPRIS with current progress (called every ~500ms from frontend)
state.media_controls.set_playback_with_progress(
playback_state.is_playing,
playback_state.position,
);
Ok(playback_state)
} }
/// Audio device information /// Audio device information
+1 -1
View File
@@ -442,7 +442,7 @@ impl Player {
} }
/// Playback state snapshot /// Playback state snapshot
#[derive(Debug, Clone, serde::Serialize)] #[derive(Debug, Clone, Default, serde::Serialize)]
pub struct PlaybackState { pub struct PlaybackState {
pub is_playing: bool, pub is_playing: bool,
pub position: u64, pub position: u64,