Commit 75082194 by olly Committed by Oliver Woodman

Simplify PlayerControlView fast forward and rewind implementation

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=221065798
parent 063f5704
...@@ -894,35 +894,28 @@ public class PlayerControlView extends FrameLayout { ...@@ -894,35 +894,28 @@ public class PlayerControlView extends FrameLayout {
} }
private void rewind() { private void rewind() {
if (rewindMs <= 0) { if (rewindMs > 0) {
return; seekTo(player.getCurrentPosition() - rewindMs);
} }
seekTo(Math.max(player.getCurrentPosition() - rewindMs, 0));
} }
private void fastForward() { private void fastForward() {
if (fastForwardMs <= 0) { if (fastForwardMs > 0) {
return; seekTo(player.getCurrentPosition() + fastForwardMs);
}
long durationMs = player.getDuration();
long seekPositionMs = player.getCurrentPosition() + fastForwardMs;
if (durationMs != C.TIME_UNSET) {
seekPositionMs = Math.min(seekPositionMs, durationMs);
} }
seekTo(seekPositionMs);
} }
private void seekTo(long positionMs) { private void seekTo(long positionMs) {
seekTo(player.getCurrentWindowIndex(), positionMs); seekTo(player.getCurrentWindowIndex(), positionMs);
} }
private void seekTo(int windowIndex, long positionMs) { private boolean seekTo(int windowIndex, long positionMs) {
boolean dispatched = controlDispatcher.dispatchSeekTo(player, windowIndex, positionMs); long durationMs = player.getDuration();
if (!dispatched) { if (durationMs != C.TIME_UNSET) {
// The seek wasn't dispatched. If the progress bar was dragged by the user to perform the positionMs = Math.min(positionMs, durationMs);
// seek then it'll now be in the wrong position. Trigger a progress update to snap it back.
updateProgress();
} }
positionMs = Math.max(positionMs, 0);
return controlDispatcher.dispatchSeekTo(player, windowIndex, positionMs);
} }
private void seekToTimeBarPosition(long positionMs) { private void seekToTimeBarPosition(long positionMs) {
...@@ -946,7 +939,12 @@ public class PlayerControlView extends FrameLayout { ...@@ -946,7 +939,12 @@ public class PlayerControlView extends FrameLayout {
} else { } else {
windowIndex = player.getCurrentWindowIndex(); windowIndex = player.getCurrentWindowIndex();
} }
seekTo(windowIndex, positionMs); boolean dispatched = seekTo(windowIndex, positionMs);
if (!dispatched) {
// The seek wasn't dispatched then the progress bar scrubber will be in the wrong position.
// Trigger a progress update to snap it back.
updateProgress();
}
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment