From 1fe366ce9f043561c43a3c9ea0b95205a414fa27 Mon Sep 17 00:00:00 2001 From: mars Date: Sun, 20 Nov 2022 00:00:21 -0700 Subject: [PATCH] Move progress length to TrackInfo --- apps/music-player/src/lib.rs | 8 ++++---- apps/music-player/src/main.rs | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/music-player/src/lib.rs b/apps/music-player/src/lib.rs index d3ecabb..e7cdd2b 100644 --- a/apps/music-player/src/lib.rs +++ b/apps/music-player/src/lib.rs @@ -34,9 +34,6 @@ pub enum LoopStatus { pub struct ProgressChanged { /// Current position into the track in seconds. pub position: f32, - - /// Length of the current track in seconds. - pub length: Option, } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] @@ -48,7 +45,7 @@ pub struct AlbumInfo { pub artists: Vec, } -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct TrackInfo { /// The title of the current track. pub title: Option, @@ -58,6 +55,9 @@ pub struct TrackInfo { /// The optional track number on the disc the album the track appears on. pub track_number: Option, + + /// Length of the track in seconds. + pub length: Option, } #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/apps/music-player/src/main.rs b/apps/music-player/src/main.rs index dec15f9..212cf68 100644 --- a/apps/music-player/src/main.rs +++ b/apps/music-player/src/main.rs @@ -40,6 +40,10 @@ impl<'a> From> for Metadata { track_number: map .get("xesam:trackNumber") .and_then(|v| TryFrom::try_from(v).ok()), + length: map + .get("xesam:length") + .and_then(|v| i64::try_from(v).ok()) + .map(|us| us as f32 / 1_000_000.0), // 1,000,000 microseconds in a second }; Self { album, track }