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: (),
|
_idle_active: (),
|
||||||
#[property(type = u32, get = Self::playlist_count)]
|
#[property(type = u32, get = Self::playlist_count)]
|
||||||
_playlist_count: (),
|
_playlist_count: (),
|
||||||
|
|
||||||
|
pub(super) queued_seek: Cell<Option<f64>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Window {
|
impl Default for Window {
|
||||||
|
@ -95,6 +97,8 @@ mod imp {
|
||||||
_duration: (),
|
_duration: (),
|
||||||
_idle_active: (),
|
_idle_active: (),
|
||||||
_playlist_count: (),
|
_playlist_count: (),
|
||||||
|
|
||||||
|
queued_seek: Cell::new(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,6 +246,23 @@ mod imp {
|
||||||
// ^ ignore
|
// ^ 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:?}"),
|
_ => event!(Level::DEBUG, "unhandled {event:?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -369,12 +390,17 @@ mod imp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn time_pos(&self) -> f64 {
|
fn time_pos(&self) -> f64 {
|
||||||
match self.mpv.get_property("time-pos") {
|
if let Some(queued_seek) = self.queued_seek.get() {
|
||||||
Ok(time_pos) => Ok(time_pos),
|
// counterfeit time-pos while the seek is ongoing
|
||||||
Err(err) if err.is_property_unavailable() => Ok(0.0), //placeholder
|
queued_seek
|
||||||
Err(err) => Err(err),
|
} 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
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn duration(&self) -> f64 {
|
fn duration(&self) -> f64 {
|
||||||
|
@ -498,9 +524,11 @@ impl Window {
|
||||||
.command(["seek", &new_position.to_string(), "absolute", "exact"])
|
.command(["seek", &new_position.to_string(), "absolute", "exact"])
|
||||||
{
|
{
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
// TODO: buffer this on fail (usually happens when the file isn't done loading)
|
Err(err) => {
|
||||||
// to repro, mash the seek forward button
|
event!(Level::INFO, "queuing seek to {new_position}: {err}");
|
||||||
Err(err) => event!(Level::ERROR, "could seek to {new_position}: {err}"),
|
self.imp().queued_seek.set(Some(new_position));
|
||||||
|
self.notify("time-pos");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue