Skip to content

Commit da6ede9

Browse files
committed
feat(mpris): Check track_id when setting position
1 parent afd6e8c commit da6ede9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/mpris_event_handler.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{collections::HashMap, process, sync::Arc, time::Instant};
22

33
use librespot_connect::Spirc;
4-
use log::{debug, warn};
4+
use log::{debug, info, warn};
55
use thiserror::Error;
66
use time::format_description::well_known::Iso8601;
77
use tokio::sync::mpsc;
@@ -723,12 +723,21 @@ impl MprisPlayerService {
723723
// * `position`: Track position in microseconds. This must be between 0 and `track_length`.
724724
async fn set_position(&self, track_id: zbus::zvariant::ObjectPath<'_>, position: TimeInUs) {
725725
debug!("org.mpris.MediaPlayer2.Player::SetPosition({track_id:?}, {position:?})");
726-
// FIXME: handle track_id
727726
if position < 0 {
728727
return;
729728
}
730729
if let Some(spirc) = &self.spirc {
731-
let _ = spirc.set_position_ms((position / 1000) as u32);
730+
let current_track_id = self.metadata.mpris.track_id.as_ref().and_then(|track_id| {
731+
track_id
732+
.to_id()
733+
.ok()
734+
.map(|id| format!("/org/librespot/track/{id}"))
735+
});
736+
if current_track_id.as_deref() == Some(track_id.as_str()) {
737+
let _ = spirc.set_position_ms((position / 1000) as u32);
738+
} else {
739+
info!("SetPosition on wrong trackId, ignoring as stale");
740+
}
732741
}
733742
}
734743

0 commit comments

Comments
 (0)