attempt at queued seeks
This commit is contained in:
parent
048ab58bf5
commit
d3641a6f33
1 changed files with 36 additions and 8 deletions
|
@ -52,6 +52,8 @@ mod imp {
|
|||
_idle_active: (),
|
||||
#[property(type = u32, get = Self::playlist_count)]
|
||||
_playlist_count: (),
|
||||
|
||||
pub(super) queued_seek: Cell<Option<f64>>,
|
||||
}
|
||||
|
||||
impl Default for Window {
|
||||
|
@ -95,6 +97,8 @@ mod imp {
|
|||
_duration: (),
|
||||
_idle_active: (),
|
||||
_playlist_count: (),
|
||||
|
||||
queued_seek: Cell::new(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -242,6 +246,23 @@ mod imp {
|
|||
// ^ ignore
|
||||
}
|
||||
|
||||
Event::PlaybackRestart => {
|
||||
if let Some(queued_seek) = window.imp().queued_seek.take() {
|
||||
// a seek was tried before and failed, try again now
|
||||
event!(Level::INFO, "performing queued seek to {queued_seek}");
|
||||
window.seek(queued_seek);
|
||||
}
|
||||
}
|
||||
|
||||
Event::EndFile(event) => {
|
||||
if let Err(err) = event.reason {
|
||||
event!(Level::ERROR, "end file error: {err}");
|
||||
}
|
||||
|
||||
// cancel queued seek always
|
||||
window.imp().queued_seek.set(None);
|
||||
}
|
||||
|
||||
_ => event!(Level::DEBUG, "unhandled {event:?}"),
|
||||
}
|
||||
}
|
||||
|
@ -369,6 +390,10 @@ mod imp {
|
|||
}
|
||||
|
||||
fn time_pos(&self) -> f64 {
|
||||
if let Some(queued_seek) = self.queued_seek.get() {
|
||||
// counterfeit time-pos while the seek is ongoing
|
||||
queued_seek
|
||||
} else {
|
||||
match self.mpv.get_property("time-pos") {
|
||||
Ok(time_pos) => Ok(time_pos),
|
||||
Err(err) if err.is_property_unavailable() => Ok(0.0), //placeholder
|
||||
|
@ -376,6 +401,7 @@ mod imp {
|
|||
}
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
fn duration(&self) -> f64 {
|
||||
let duration = match self.mpv.get_property::<f64>("duration") {
|
||||
|
@ -498,9 +524,11 @@ impl Window {
|
|||
.command(["seek", &new_position.to_string(), "absolute", "exact"])
|
||||
{
|
||||
Ok(()) => {}
|
||||
// TODO: buffer this on fail (usually happens when the file isn't done loading)
|
||||
// to repro, mash the seek forward button
|
||||
Err(err) => event!(Level::ERROR, "could seek to {new_position}: {err}"),
|
||||
Err(err) => {
|
||||
event!(Level::INFO, "queuing seek to {new_position}: {err}");
|
||||
self.imp().queued_seek.set(Some(new_position));
|
||||
self.notify("time-pos");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue