diff --git a/resources/playbar.blp b/resources/playbar.blp index 93874da..c3f2008 100644 --- a/resources/playbar.blp +++ b/resources/playbar.blp @@ -150,6 +150,7 @@ template $AudreyUiPlaybar: Adw.Bin { Button { icon-name: "non-starred"; valign: center; + sensitive: bind template.idle-active inverted; } Button { diff --git a/src/mpv/event.rs b/src/mpv/event.rs index 4234999..0177236 100644 --- a/src/mpv/event.rs +++ b/src/mpv/event.rs @@ -13,7 +13,7 @@ pub enum Event { //ClientMessage(ClientMessageEvent), TODO VideoReconfig, AudioReconfig, - //Seek, + Seek, PlaybackRestart, PropertyChange(PropertyEvent), //QueueOverflow, diff --git a/src/mpv/handle.rs b/src/mpv/handle.rs index b2923d6..1c0275d 100644 --- a/src/mpv/handle.rs +++ b/src/mpv/handle.rs @@ -253,6 +253,8 @@ impl Handle { })) } + ffi::mpv_event_id_MPV_EVENT_SEEK => Some(MpvEvent::Seek), + 11 => Some(MpvEvent::Unknown(event.event_id)), _ => todo!("event {}", event.event_id), diff --git a/src/ui/playbar.rs b/src/ui/playbar.rs index 71b6eb9..316602c 100644 --- a/src/ui/playbar.rs +++ b/src/ui/playbar.rs @@ -79,58 +79,42 @@ mod imp { fn on_play_position_seek( &self, _scroll_type: gtk::ScrollType, - _value: f64, + value: f64, _range: >k::Range, ) -> bool { - /* - let playbin = self.playbin.upgrade().unwrap(); - if range.adjustment().lower() < range.adjustment().upper() { - playbin.seek(value); - } - false*/ - todo!() + self.window().seek(value); + false } #[template_callback] fn on_skip_forward_clicked(&self) { - /* - let playbin = self.playbin.upgrade().unwrap(); - playbin.go_to_next_track();*/ - todo!() + self.window().playlist_next(); } #[template_callback] fn on_skip_backward_clicked(&self) { - /* - let playbin = self.playbin.upgrade().unwrap(); - playbin.go_to_prev_track();*/ - todo!() + self.window().playlist_prev(); } #[template_callback] fn seek_backward(&self) { - /* - let playbin = self.playbin.upgrade().unwrap(); // 10 seconds - let mut new_position = playbin.position() - 10.0; + let mut new_position = self.window().time_pos() - 10.0; if new_position < 0.0 { new_position = 0.0; } - playbin.seek(new_position);*/ - todo!() + self.window().seek(new_position); } #[template_callback] fn seek_forward(&self) { - /* - let playbin = self.playbin.upgrade().unwrap(); // 10 seconds - let mut new_position = playbin.position() + 10.0; - if new_position > playbin.duration() { - new_position = playbin.duration(); + let new_position = self.window().time_pos() + 10.0; + if new_position > self.window().duration() { + // just seek to the next track + self.on_skip_forward_clicked(); } - playbin.seek(new_position);*/ - todo!() + self.window().seek(new_position); } #[template_callback] diff --git a/src/ui/window.rs b/src/ui/window.rs index 959d691..abe5286 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -403,10 +403,15 @@ mod imp { .unwrap(); // sanity check - assert_eq!( - song.stream_url(), - self.mpv.get_property::("path").unwrap() - ); + match self.mpv.get_property::("path") { + Ok(path) => assert_eq!(song.stream_url(), path), + Err(err) if err.is_property_unavailable() => { + // NOTE: this happens between EndFile and StartFile + event!(Level::WARN, "can't do sanity check, path is unavailable") + } + Err(err) => Err(err).unwrap(), + }; + Some(song) } } @@ -463,4 +468,19 @@ impl Window { self.imp().api.replace(Some(Rc::new(api))); self.set_can_click_shuffle_all(true); } + + pub fn playlist_next(&self) { + self.imp().mpv.command(["playlist-next"]).unwrap(); + } + + pub fn playlist_prev(&self) { + self.imp().mpv.command(["playlist-prev"]).unwrap(); + } + + pub fn seek(&self, new_position: f64) { + self.imp() + .mpv + .command(["seek", &new_position.to_string(), "absolute", "exact"]) + .unwrap(); + } }