Simplify DefaultControlDispatcher by using Player methods

PiperOrigin-RevId: 379732136
This commit is contained in:
kimvde 2021-06-16 17:00:44 +01:00 committed by Oliver Woodman
parent 63f12f0216
commit 56e97783eb

View File

@ -28,7 +28,6 @@ public class DefaultControlDispatcher implements ControlDispatcher {
private static final int MAX_POSITION_FOR_SEEK_TO_PREVIOUS = 3000; private static final int MAX_POSITION_FOR_SEEK_TO_PREVIOUS = 3000;
private final Timeline.Window window;
private final long rewindIncrementMs; private final long rewindIncrementMs;
private final long fastForwardIncrementMs; private final long fastForwardIncrementMs;
@ -48,7 +47,6 @@ public class DefaultControlDispatcher implements ControlDispatcher {
public DefaultControlDispatcher(long fastForwardIncrementMs, long rewindIncrementMs) { public DefaultControlDispatcher(long fastForwardIncrementMs, long rewindIncrementMs) {
this.fastForwardIncrementMs = fastForwardIncrementMs; this.fastForwardIncrementMs = fastForwardIncrementMs;
this.rewindIncrementMs = rewindIncrementMs; this.rewindIncrementMs = rewindIncrementMs;
window = new Timeline.Window();
} }
@Override @Override
@ -75,16 +73,14 @@ public class DefaultControlDispatcher implements ControlDispatcher {
if (timeline.isEmpty() || player.isPlayingAd()) { if (timeline.isEmpty() || player.isPlayingAd()) {
return true; return true;
} }
int windowIndex = player.getCurrentWindowIndex(); boolean isUnseekableLiveStream =
timeline.getWindow(windowIndex, window); player.isCurrentWindowLive() && !player.isCurrentWindowSeekable();
int previousWindowIndex = player.getPreviousWindowIndex(); if (player.hasPrevious()
boolean isUnseekableLiveStream = window.isLive() && !window.isSeekable;
if (previousWindowIndex != C.INDEX_UNSET
&& (player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS && (player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS
|| isUnseekableLiveStream)) { || isUnseekableLiveStream)) {
player.seekTo(previousWindowIndex, C.TIME_UNSET); player.previous();
} else if (!isUnseekableLiveStream) { } else if (!isUnseekableLiveStream) {
player.seekTo(windowIndex, /* positionMs= */ 0); player.seekTo(/* positionMs= */ 0);
} }
return true; return true;
} }
@ -95,13 +91,10 @@ public class DefaultControlDispatcher implements ControlDispatcher {
if (timeline.isEmpty() || player.isPlayingAd()) { if (timeline.isEmpty() || player.isPlayingAd()) {
return true; return true;
} }
int windowIndex = player.getCurrentWindowIndex(); if (player.hasNext()) {
timeline.getWindow(windowIndex, window); player.next();
int nextWindowIndex = player.getNextWindowIndex(); } else if (player.isCurrentWindowLive() && player.isCurrentWindowDynamic()) {
if (nextWindowIndex != C.INDEX_UNSET) { player.seekToDefaultPosition();
player.seekTo(nextWindowIndex, C.TIME_UNSET);
} else if (window.isLive() && window.isDynamic) {
player.seekTo(windowIndex, C.TIME_UNSET);
} }
return true; return true;
} }
@ -176,6 +169,6 @@ public class DefaultControlDispatcher implements ControlDispatcher {
positionMs = min(positionMs, durationMs); positionMs = min(positionMs, durationMs);
} }
positionMs = max(positionMs, 0); positionMs = max(positionMs, 0);
player.seekTo(player.getCurrentWindowIndex(), positionMs); player.seekTo(positionMs);
} }
} }