Replace music player SetPosition message with relative Seek
This commit is contained in:
parent
448435eb8c
commit
2bef47a65a
|
@ -104,6 +104,6 @@ pub enum OutMsg {
|
||||||
/// Sets the volume. Values are clamped to 0.0 to 1.0.
|
/// Sets the volume. Values are clamped to 0.0 to 1.0.
|
||||||
SetVolume { volume: f32 },
|
SetVolume { volume: f32 },
|
||||||
|
|
||||||
/// Set the current track position in seconds.
|
/// Seeks the current track's position in seconds.
|
||||||
SetPosition { position: f32 },
|
Seek { offset: f32 },
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,10 +111,8 @@ async fn on_message(
|
||||||
OutMsg::Stop => player.stop().await?,
|
OutMsg::Stop => player.stop().await?,
|
||||||
OutMsg::Previous => player.previous().await?,
|
OutMsg::Previous => player.previous().await?,
|
||||||
OutMsg::Next => player.next().await?,
|
OutMsg::Next => player.next().await?,
|
||||||
OutMsg::SetPosition { position } => {
|
OutMsg::Seek { offset } => {
|
||||||
let current = player.position().await?;
|
let offset = (offset * 1_000_000.0) as i64; // Seconds to microseconds
|
||||||
let next = (position * 1_000_000.0) as i64; // Seconds to microseconds
|
|
||||||
let offset = next - current;
|
|
||||||
player.seek(offset).await?;
|
player.seek(offset).await?;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -149,14 +149,14 @@ impl Container for MusicPlayerWidget {
|
||||||
Some(position * self.duration_secs)
|
Some(position * self.duration_secs)
|
||||||
} else if self.position_updating {
|
} else if self.position_updating {
|
||||||
let position = self.slider.get_position() * self.duration_secs;
|
let position = self.slider.get_position() * self.duration_secs;
|
||||||
let msg = OutMsg::SetPosition { position };
|
let offset = position - self.position_secs;
|
||||||
|
let msg = OutMsg::Seek { offset };
|
||||||
self.send_message(&msg);
|
self.send_message(&msg);
|
||||||
|
self.position_secs = position;
|
||||||
self.position_updating = false;
|
self.position_updating = false;
|
||||||
Some(position)
|
Some(position)
|
||||||
} else if let PlaybackStatus::Playing = self.status {
|
} else if let PlaybackStatus::Playing = self.status {
|
||||||
self.position_secs += dt;
|
self.position_secs += dt;
|
||||||
self.slider
|
|
||||||
.set_position(self.position_secs / self.duration_secs);
|
|
||||||
Some(self.position_secs)
|
Some(self.position_secs)
|
||||||
} else if self.position_dirty {
|
} else if self.position_dirty {
|
||||||
self.position_dirty = false;
|
self.position_dirty = false;
|
||||||
|
@ -168,6 +168,8 @@ impl Container for MusicPlayerWidget {
|
||||||
if let Some(position) = position_display {
|
if let Some(position) = position_display {
|
||||||
self.position_dirty = false;
|
self.position_dirty = false;
|
||||||
self.position.set_text(&Self::format_time(position));
|
self.position.set_text(&Self::format_time(position));
|
||||||
|
self.slider
|
||||||
|
.set_position(self.position_secs / self.duration_secs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.previous.was_clicked() {
|
if self.previous.was_clicked() {
|
||||||
|
|
Loading…
Reference in New Issue