diff --git a/src/ui/playbar.rs b/src/ui/playbar.rs index 08e312b..a64903c 100644 --- a/src/ui/playbar.rs +++ b/src/ui/playbar.rs @@ -89,7 +89,7 @@ mod imp { value: f64, _range: >k::Range, ) -> bool { - self.window().seek(value); + self.window().set_time_pos(value); false } diff --git a/src/ui/window.rs b/src/ui/window.rs index 0021e7b..d9c8c86 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -185,12 +185,7 @@ mod imp { #[weak(rename_to = window)] self.obj(), move |_, _, _| { - let new_position = window.time_pos() - 10.0; - if new_position < 0.0 { - window.seek(0.0); - } else { - window.seek(new_position); - } + window.seek(-10.0); }, )) .build(); @@ -200,17 +195,7 @@ mod imp { #[weak(rename_to = window)] self.obj(), move |_, _, _| { - let new_position = window.time_pos() + 10.0; - if new_position > window.duration() { - // just seek to the next track - if window.playlist_pos() + 1 < window.playlist_count() { - window.playlist_next(); - } else { - window.playlist_play_index(None); - } - } else { - window.seek(new_position); - } + window.seek(10.0); }, )) .build(); @@ -935,7 +920,7 @@ impl Window { self.imp().mpv.command(["playlist-prev"]).unwrap(); } - pub fn seek(&self, new_position: f64) { + pub fn set_time_pos(&self, new_position: f64) { use imp::State; match self.imp().state.get() { @@ -956,6 +941,36 @@ impl Window { } } + pub fn seek(&self, offset: f64) { + use imp::State; + + match self.imp().state.get() { + State::Active | State::Seeking => { + self.imp() + .mpv + .command(["seek", &offset.to_string()]) + .unwrap(); + } + + State::FileLoading => { + let mut new_position = self.time_pos() + offset; + if new_position < 0.0 { + new_position = 0.0; + } + let duration = self.duration(); + if new_position > duration { + new_position = duration; + } + + event!(Level::INFO, "queuing seek to {new_position}"); + self.imp().queued_seek.set(Some(new_position)); + self.notify("time-pos"); + } + + other => panic!("can not seek when im state {other:?}"), + } + } + pub fn playlist_move(&self, from: u32, to: u32) { // NOTE: for mpv, to refers to the "gap" right before i // so playlist-move i 0 makes a track the first