diff --git a/apps/music-player/src/lib.rs b/apps/music-player/src/lib.rs index e7cdd2b..fa0e96d 100644 --- a/apps/music-player/src/lib.rs +++ b/apps/music-player/src/lib.rs @@ -104,6 +104,6 @@ pub enum OutMsg { /// Sets the volume. Values are clamped to 0.0 to 1.0. SetVolume { volume: f32 }, - /// Set the current track position in seconds. - SetPosition { position: f32 }, + /// Seeks the current track's position in seconds. + Seek { offset: f32 }, } diff --git a/apps/music-player/src/main.rs b/apps/music-player/src/main.rs index 27b65a4..fb647ee 100644 --- a/apps/music-player/src/main.rs +++ b/apps/music-player/src/main.rs @@ -111,10 +111,8 @@ async fn on_message( OutMsg::Stop => player.stop().await?, OutMsg::Previous => player.previous().await?, OutMsg::Next => player.next().await?, - OutMsg::SetPosition { position } => { - let current = player.position().await?; - let next = (position * 1_000_000.0) as i64; // Seconds to microseconds - let offset = next - current; + OutMsg::Seek { offset } => { + let offset = (offset * 1_000_000.0) as i64; // Seconds to microseconds player.seek(offset).await?; } _ => {} diff --git a/scripts/sao-ui/src/music_player.rs b/scripts/sao-ui/src/music_player.rs index 4c0d992..ab05398 100644 --- a/scripts/sao-ui/src/music_player.rs +++ b/scripts/sao-ui/src/music_player.rs @@ -149,14 +149,14 @@ impl Container for MusicPlayerWidget { Some(position * self.duration_secs) } else if self.position_updating { 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.position_secs = position; self.position_updating = false; Some(position) } else if let PlaybackStatus::Playing = self.status { self.position_secs += dt; - self.slider - .set_position(self.position_secs / self.duration_secs); Some(self.position_secs) } else if self.position_dirty { self.position_dirty = false; @@ -168,6 +168,8 @@ impl Container for MusicPlayerWidget { if let Some(position) = position_display { self.position_dirty = false; self.position.set_text(&Self::format_time(position)); + self.slider + .set_position(self.position_secs / self.duration_secs); } if self.previous.was_clicked() {