restore seeking

This commit is contained in:
Erica Z 2024-11-05 10:16:22 +01:00
parent a6378b281a
commit 5e62838371
5 changed files with 40 additions and 33 deletions

View file

@ -150,6 +150,7 @@ template $AudreyUiPlaybar: Adw.Bin {
Button { Button {
icon-name: "non-starred"; icon-name: "non-starred";
valign: center; valign: center;
sensitive: bind template.idle-active inverted;
} }
Button { Button {

View file

@ -13,7 +13,7 @@ pub enum Event {
//ClientMessage(ClientMessageEvent), TODO //ClientMessage(ClientMessageEvent), TODO
VideoReconfig, VideoReconfig,
AudioReconfig, AudioReconfig,
//Seek, Seek,
PlaybackRestart, PlaybackRestart,
PropertyChange(PropertyEvent), PropertyChange(PropertyEvent),
//QueueOverflow, //QueueOverflow,

View file

@ -253,6 +253,8 @@ impl Handle {
})) }))
} }
ffi::mpv_event_id_MPV_EVENT_SEEK => Some(MpvEvent::Seek),
11 => Some(MpvEvent::Unknown(event.event_id)), 11 => Some(MpvEvent::Unknown(event.event_id)),
_ => todo!("event {}", event.event_id), _ => todo!("event {}", event.event_id),

View file

@ -79,58 +79,42 @@ mod imp {
fn on_play_position_seek( fn on_play_position_seek(
&self, &self,
_scroll_type: gtk::ScrollType, _scroll_type: gtk::ScrollType,
_value: f64, value: f64,
_range: &gtk::Range, _range: &gtk::Range,
) -> bool { ) -> bool {
/* self.window().seek(value);
let playbin = self.playbin.upgrade().unwrap(); false
if range.adjustment().lower() < range.adjustment().upper() {
playbin.seek(value);
}
false*/
todo!()
} }
#[template_callback] #[template_callback]
fn on_skip_forward_clicked(&self) { fn on_skip_forward_clicked(&self) {
/* self.window().playlist_next();
let playbin = self.playbin.upgrade().unwrap();
playbin.go_to_next_track();*/
todo!()
} }
#[template_callback] #[template_callback]
fn on_skip_backward_clicked(&self) { fn on_skip_backward_clicked(&self) {
/* self.window().playlist_prev();
let playbin = self.playbin.upgrade().unwrap();
playbin.go_to_prev_track();*/
todo!()
} }
#[template_callback] #[template_callback]
fn seek_backward(&self) { fn seek_backward(&self) {
/*
let playbin = self.playbin.upgrade().unwrap();
// 10 seconds // 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 { if new_position < 0.0 {
new_position = 0.0; new_position = 0.0;
} }
playbin.seek(new_position);*/ self.window().seek(new_position);
todo!()
} }
#[template_callback] #[template_callback]
fn seek_forward(&self) { fn seek_forward(&self) {
/*
let playbin = self.playbin.upgrade().unwrap();
// 10 seconds // 10 seconds
let mut new_position = playbin.position() + 10.0; let new_position = self.window().time_pos() + 10.0;
if new_position > playbin.duration() { if new_position > self.window().duration() {
new_position = playbin.duration(); // just seek to the next track
self.on_skip_forward_clicked();
} }
playbin.seek(new_position);*/ self.window().seek(new_position);
todo!()
} }
#[template_callback] #[template_callback]

View file

@ -403,10 +403,15 @@ mod imp {
.unwrap(); .unwrap();
// sanity check // sanity check
assert_eq!( match self.mpv.get_property::<String>("path") {
song.stream_url(), Ok(path) => assert_eq!(song.stream_url(), path),
self.mpv.get_property::<String>("path").unwrap() 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) Some(song)
} }
} }
@ -463,4 +468,19 @@ impl Window {
self.imp().api.replace(Some(Rc::new(api))); self.imp().api.replace(Some(Rc::new(api)));
self.set_can_click_shuffle_all(true); 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();
}
} }