Skip to content

Commit 9537915

Browse files
committed
feat: Support duration + seeking on macos.
1 parent 97b8bec commit 9537915

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

crates/ytermusic/src/structures/media.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::sound_action::SoundAction;
1616
pub struct Media {
1717
controls: Option<MediaControls>,
1818

19-
current_meta: Option<(String, String, String)>,
19+
current_meta: Option<(String, String, String, Option<Duration>)>,
2020
current_playback: Option<MediaPlayback>,
2121
}
2222

@@ -65,12 +65,16 @@ impl Media {
6565
media_meta.title.unwrap_or("").to_string(),
6666
media_meta.album.unwrap_or("").to_string(),
6767
media_meta.artist.unwrap_or("").to_string(),
68+
sink.duration()
69+
.map(|duration| Duration::from_secs(duration as u64)),
6870
))
6971
{
7072
self.current_meta = Some((
7173
media_meta.title.unwrap_or("").to_string(),
7274
media_meta.album.unwrap_or("").to_string(),
7375
media_meta.artist.unwrap_or("").to_string(),
76+
sink.duration()
77+
.map(|duration| Duration::from_secs(duration as u64)),
7478
));
7579
e.set_metadata(media_meta)?;
7680
}
@@ -138,7 +142,7 @@ fn connect(mpris: &mut MediaControls, sender: Sender<SoundAction>) -> Result<(),
138142
shutdown();
139143
}
140144
MediaControlEvent::SetVolume(e) => {
141-
todo!("Implement volume setting {e:?}");
145+
sender.send(SoundAction::SetVolume(e as f32)).unwrap();
142146
}
143147
})
144148
}

crates/ytermusic/src/structures/sound_action.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use crate::{
1515
/// Actions that can be sent to the player from other services
1616
#[derive(Debug, Clone)]
1717
pub enum SoundAction {
18+
/// Set the volume of the player to the given value
19+
SetVolume(f32),
1820
Cleanup,
1921
PlayPause,
2022
RestartPlayer,
@@ -53,6 +55,7 @@ impl SoundAction {
5355

5456
pub fn apply_sound_action(self, player: &mut PlayerState) {
5557
match self {
58+
Self::SetVolume(volume) => player.sink.set_volume((volume * 100.) as i32),
5659
Self::SeekTo(time) => player.sink.seek_to(time),
5760
Self::Backward => player.sink.seek_bw(),
5861
Self::Forward => player.sink.seek_fw(),

0 commit comments

Comments
 (0)