Compare commits

...

4 commits

Author SHA1 Message Date
fd44d3280a fix seek command 2024-11-11 12:00:43 +01:00
4060213e80 time-pos notification 2024-11-11 10:06:53 +01:00
e72a690be2 sure 2024-11-11 10:06:53 +01:00
1d9318eb92 fix 2024-11-11 10:06:53 +01:00
2 changed files with 30 additions and 22 deletions

View file

@ -128,8 +128,9 @@ mod imp {
if new_position > self.window().duration() {
// just seek to the next track
self.on_skip_forward_clicked();
} else {
self.window().seek(new_position);
}
self.window().seek(new_position);
}
#[template_callback]

View file

@ -12,12 +12,12 @@ mod imp {
use zbus::object_server::InterfaceRef;
#[derive(Debug, Copy, Clone)]
enum State {
pub(super) enum State {
Idle,
FileLoading,
FileLoaded,
FileLoaded, // internal?
Active,
FileEnded,
FileEnded, // internal?
Seeking,
}
@ -25,7 +25,7 @@ mod imp {
#[template(resource = "/eu/callcc/audrey/window.ui")]
#[properties(wrapper_type = super::Window)]
pub struct Window {
state: Cell<State>,
pub(super) state: Cell<State>,
#[template_child]
pub(super) playbar: TemplateChild<crate::ui::Playbar>,
@ -175,8 +175,10 @@ mod imp {
move || match window.upgrade() {
None => glib::ControlFlow::Break,
Some(window) => {
if !window.idle_active() && !window.pause() {
window.notify("time-pos");
match window.imp().state.get() {
State::Idle | State::FileLoading | State::Seeking => {},
State::Active => window.notify("time-pos"),
other => unreachable!("{other:?}"),
}
glib::ControlFlow::Continue
}
@ -506,6 +508,9 @@ mod imp {
}
self.state.set(State::FileLoading);
// make sure this is reported as 0
self.obj().notify("time-pos");
event!(Level::INFO, "StartFile");
self.obj().notify("song");
self.buffering_start();
@ -538,9 +543,6 @@ mod imp {
{
handle.abort();
}
// make sure this is reported as 0
self.obj().notify("time-pos");
}
fn on_file_loaded(&self) {
@ -596,7 +598,6 @@ mod imp {
event!(Level::INFO, "PlaybackRestart");
self.buffering_end();
self.obj().notify("time-pos");
if let Some(queued_seek) = self.queued_seek.take() {
// a seek was tried before and failed, try again now
@ -617,6 +618,9 @@ mod imp {
}
self.state.set(State::FileEnded);
// make sure the seekbar looks full
self.obj().notify("time-pos");
self.obj().notify("song");
self.buffering_end();
@ -628,9 +632,6 @@ mod imp {
self.queued_seek.set(None);
self.obj().set_playing_cover_art(None::<gdk::Texture>);
// make sure the seekbar looks full
self.obj().notify("time-pos");
}
#[template_callback]
@ -760,17 +761,23 @@ impl Window {
}
pub fn seek(&self, new_position: f64) {
match self
.imp()
.mpv
.command(["seek", &new_position.to_string(), "absolute", "exact"])
{
Ok(()) => {}
Err(err) => {
event!(Level::INFO, "queuing seek to {new_position}: {err}");
use imp::State;
match self.imp().state.get() {
State::Active | State::Seeking => {
self.imp()
.mpv
.command(["seek", &new_position.to_string(), "absolute+exact"])
.unwrap();
}
State::FileLoading => {
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 in state {other:?}"),
}
}