player.rs: Improve the fast-forward handling

Previously if you hit fast-forward but the offset remaining was
let that the amount you wanted to seek, it would do nothing.
Now it resets the stream and seekbar to the start.

Eventually this will just move on to the next episode in the
Queue once that's implemented.
This commit is contained in:
Zander Brown 2018-11-05 21:39:07 +00:00 committed by Jordan Petridis
parent 85387a0a9b
commit fbda4c76f0
No known key found for this signature in database
GPG Key ID: E8523968931763BE

View File

@ -553,21 +553,32 @@ impl PlayerExt for PlayerWidget {
// Adapted from https://github.com/philn/glide/blob/b52a65d99daeab0b487f79a0e1ccfad0cd433e22/src/player_context.rs#L219-L245
fn seek(&self, offset: ClockTime, direction: SeekDirection) {
// How far into the podcast we are
let position = self.player.get_position();
if position.is_none() || offset.is_none() {
return;
}
// How much podcast we have
let duration = self.player.get_duration();
let destination = match direction {
// If we are more than `offset` into the podcast, jump back that far
SeekDirection::Backwards if position >= offset => Some(position - offset),
// If we haven't played `offset` yet just restart the podcast
SeekDirection::Backwards if position < offset => Some(ClockTime::from_seconds(0)),
// If we have more than `offset` remaining jump forward they amount
SeekDirection::Forward if !duration.is_none() && position + offset <= duration => {
Some(position + offset)
}
// We don't have `offset` remaining just move to the end (ending playback)
SeekDirection::Forward if !duration.is_none() && position + offset > duration => {
Some(duration)
}
// Who knows what's going on ¯\_(ツ)_/¯
_ => None,
};
// If we calucated a new position, jump to it
destination.map(|d| self.player.seek(d));
}