mirror of
https://github.com/librespot-org/librespot.git
synced 2025-10-03 17:59:24 +02:00
feat(mpris): Check track_id when setting position
This commit is contained in:
parent
b0e0393b87
commit
4c37f2b8f4
1 changed files with 12 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
use std::{collections::HashMap, process, sync::Arc, time::Instant};
|
use std::{collections::HashMap, process, sync::Arc, time::Instant};
|
||||||
|
|
||||||
use librespot_connect::Spirc;
|
use librespot_connect::Spirc;
|
||||||
use log::{debug, warn};
|
use log::{debug, info, warn};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use time::format_description::well_known::Iso8601;
|
use time::format_description::well_known::Iso8601;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
@ -723,12 +723,21 @@ impl MprisPlayerService {
|
||||||
// * `position`: Track position in microseconds. This must be between 0 and `track_length`.
|
// * `position`: Track position in microseconds. This must be between 0 and `track_length`.
|
||||||
async fn set_position(&self, track_id: zbus::zvariant::ObjectPath<'_>, position: TimeInUs) {
|
async fn set_position(&self, track_id: zbus::zvariant::ObjectPath<'_>, position: TimeInUs) {
|
||||||
debug!("org.mpris.MediaPlayer2.Player::SetPosition({track_id:?}, {position:?})");
|
debug!("org.mpris.MediaPlayer2.Player::SetPosition({track_id:?}, {position:?})");
|
||||||
// FIXME: handle track_id
|
|
||||||
if position < 0 {
|
if position < 0 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Some(spirc) = &self.spirc {
|
if let Some(spirc) = &self.spirc {
|
||||||
let _ = spirc.set_position_ms((position / 1000) as u32);
|
let current_track_id = self.metadata.mpris.track_id.as_ref().and_then(|track_id| {
|
||||||
|
track_id
|
||||||
|
.to_id()
|
||||||
|
.ok()
|
||||||
|
.map(|id| format!("/org/librespot/track/{id}"))
|
||||||
|
});
|
||||||
|
if current_track_id.as_deref() == Some(track_id.as_str()) {
|
||||||
|
let _ = spirc.set_position_ms((position / 1000) as u32);
|
||||||
|
} else {
|
||||||
|
info!("SetPosition on wrong trackId, ignoring as stale");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue