feat(mpris): Emit Seeked signal
* Add Seeked signal to Mpris interface The Mpris2 spec includes a `Seeked` signal which should be fired when the track position changes in an unexpected way i.e. when the user seeks to a different part of the track. This PR implements this signal on seek events and also when a new track begins. The latter is not strictly required but has been observed in other players (e.g. VLC). Closes #1492 * chore: Use `send_mpris()` and `Duration` for conversion * doc: Update CHANGELOG --------- Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
This commit is contained in:
@@ -415,6 +415,8 @@ impl Spotify {
|
||||
/// Seek in the currently played [Playable] played by the [Player].
|
||||
pub fn seek(&self, position_ms: u32) {
|
||||
self.send_worker(WorkerCommand::Seek(position_ms));
|
||||
#[cfg(feature = "mpris")]
|
||||
self.notify_seeked(position_ms);
|
||||
}
|
||||
|
||||
/// Seek relatively to the current playback position of the [Player].
|
||||
@@ -429,6 +431,19 @@ impl Spotify {
|
||||
self.cfg.state().volume
|
||||
}
|
||||
|
||||
/// Send a Seeked signal on Mpris interface
|
||||
#[cfg(feature = "mpris")]
|
||||
pub fn notify_seeked(&self, position_ms: u32) {
|
||||
let new_position = Duration::from_millis(position_ms.into());
|
||||
let command = MprisCommand::EmitSeekedStatus(
|
||||
new_position
|
||||
.as_micros()
|
||||
.try_into()
|
||||
.expect("track position exceeds MPRIS datatype"),
|
||||
);
|
||||
self.send_mpris(command);
|
||||
}
|
||||
|
||||
/// Set the current volume of the [Player]. If `notify` is true, also notify MPRIS clients about
|
||||
/// the update.
|
||||
pub fn set_volume(&self, volume: u16, notify: bool) {
|
||||
|
||||
Reference in New Issue
Block a user