Add shortcut methods to query next or previous window index.

This functionality is most likely needed by UI modules which currently need
to obtain the timeline, the current repeat and shuffle modes and are only then
able to query the next/previous window index using this information.

Adding these methods simplifies these cumbersome requests.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=166181202
This commit is contained in:
tonihei 2017-08-23 03:29:21 -07:00 committed by Oliver Woodman
parent 2c8d5f846e
commit bd81181892
8 changed files with 74 additions and 12 deletions

View file

@ -371,6 +371,16 @@ public final class CastPlayer implements Player {
return 0; return 0;
} }
@Override
public int getNextWindowIndex() {
return C.INDEX_UNSET;
}
@Override
public int getPreviousWindowIndex() {
return C.INDEX_UNSET;
}
@Override @Override
public long getDuration() { public long getDuration() {
return currentTimeline.isEmpty() ? C.TIME_UNSET return currentTimeline.isEmpty() ? C.TIME_UNSET

View file

@ -126,8 +126,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
if (timeline.isEmpty()) { if (timeline.isEmpty()) {
return; return;
} }
int previousWindowIndex = timeline.getPreviousWindowIndex(player.getCurrentWindowIndex(), int previousWindowIndex = player.getPreviousWindowIndex();
player.getRepeatMode(), false);
if (player.getCurrentPosition() > MAX_POSITION_FOR_SEEK_TO_PREVIOUS if (player.getCurrentPosition() > MAX_POSITION_FOR_SEEK_TO_PREVIOUS
|| previousWindowIndex == C.INDEX_UNSET) { || previousWindowIndex == C.INDEX_UNSET) {
player.seekTo(0); player.seekTo(0);
@ -154,8 +153,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
if (timeline.isEmpty()) { if (timeline.isEmpty()) {
return; return;
} }
int nextWindowIndex = timeline.getNextWindowIndex(player.getCurrentWindowIndex(), int nextWindowIndex = player.getNextWindowIndex();
player.getRepeatMode(), false);
if (nextWindowIndex != C.INDEX_UNSET) { if (nextWindowIndex != C.INDEX_UNSET) {
player.seekTo(nextWindowIndex, C.TIME_UNSET); player.seekTo(nextWindowIndex, C.TIME_UNSET);
} }
@ -186,3 +184,4 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
} }
} }

View file

@ -502,6 +502,16 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public int getNextWindowIndex() {
throw new UnsupportedOperationException();
}
@Override
public int getPreviousWindowIndex() {
throw new UnsupportedOperationException();
}
@Override @Override
public long getDuration() { public long getDuration() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();

View file

@ -317,6 +317,18 @@ import java.util.concurrent.CopyOnWriteArraySet;
} }
} }
@Override
public int getNextWindowIndex() {
return timeline.getNextWindowIndex(getCurrentWindowIndex(), getRepeatMode(),
getShuffleModeEnabled());
}
@Override
public int getPreviousWindowIndex() {
return timeline.getPreviousWindowIndex(getCurrentWindowIndex(), getRepeatMode(),
getShuffleModeEnabled());
}
@Override @Override
public long getDuration() { public long getDuration() {
if (timeline.isEmpty()) { if (timeline.isEmpty()) {

View file

@ -363,6 +363,20 @@ public interface Player {
*/ */
int getCurrentWindowIndex(); int getCurrentWindowIndex();
/**
* Returns the index of the next timeline window to be played, which may depend on the current
* repeat mode and whether shuffle mode is enabled. Returns {@link C#INDEX_UNSET} if the window
* currently being played is the last window.
*/
int getNextWindowIndex();
/**
* Returns the index of the previous timeline window to be played, which may depend on the current
* repeat mode and whether shuffle mode is enabled. Returns {@link C#INDEX_UNSET} if the window
* currently being played is the first window.
*/
int getPreviousWindowIndex();
/** /**
* Returns the duration of the current window in milliseconds, or {@link C#TIME_UNSET} if the * Returns the duration of the current window in milliseconds, or {@link C#TIME_UNSET} if the
* duration is not known. * duration is not known.

View file

@ -754,6 +754,16 @@ public class SimpleExoPlayer implements ExoPlayer {
return player.getCurrentWindowIndex(); return player.getCurrentWindowIndex();
} }
@Override
public int getNextWindowIndex() {
return player.getNextWindowIndex();
}
@Override
public int getPreviousWindowIndex() {
return player.getPreviousWindowIndex();
}
@Override @Override
public long getDuration() { public long getDuration() {
return player.getDuration(); return player.getDuration();

View file

@ -675,11 +675,8 @@ public class PlaybackControlView extends FrameLayout {
timeline.getWindow(windowIndex, window); timeline.getWindow(windowIndex, window);
isSeekable = window.isSeekable; isSeekable = window.isSeekable;
enablePrevious = isSeekable || !window.isDynamic enablePrevious = isSeekable || !window.isDynamic
|| timeline.getPreviousWindowIndex(windowIndex, player.getRepeatMode(), false) || player.getPreviousWindowIndex() != C.INDEX_UNSET;
!= C.INDEX_UNSET; enableNext = window.isDynamic || player.getNextWindowIndex() != C.INDEX_UNSET;
enableNext = window.isDynamic
|| timeline.getNextWindowIndex(windowIndex, player.getRepeatMode(), false)
!= C.INDEX_UNSET;
if (player.isPlayingAd()) { if (player.isPlayingAd()) {
// Always hide player controls during ads. // Always hide player controls during ads.
hide(); hide();
@ -863,8 +860,7 @@ public class PlaybackControlView extends FrameLayout {
} }
int windowIndex = player.getCurrentWindowIndex(); int windowIndex = player.getCurrentWindowIndex();
timeline.getWindow(windowIndex, window); timeline.getWindow(windowIndex, window);
int previousWindowIndex = timeline.getPreviousWindowIndex(windowIndex, player.getRepeatMode(), int previousWindowIndex = player.getPreviousWindowIndex();
false);
if (previousWindowIndex != C.INDEX_UNSET if (previousWindowIndex != C.INDEX_UNSET
&& (player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS && (player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS
|| (window.isDynamic && !window.isSeekable))) { || (window.isDynamic && !window.isSeekable))) {
@ -880,7 +876,7 @@ public class PlaybackControlView extends FrameLayout {
return; return;
} }
int windowIndex = player.getCurrentWindowIndex(); int windowIndex = player.getCurrentWindowIndex();
int nextWindowIndex = timeline.getNextWindowIndex(windowIndex, player.getRepeatMode(), false); int nextWindowIndex = player.getNextWindowIndex();
if (nextWindowIndex != C.INDEX_UNSET) { if (nextWindowIndex != C.INDEX_UNSET) {
seekTo(nextWindowIndex, C.TIME_UNSET); seekTo(nextWindowIndex, C.TIME_UNSET);
} else if (timeline.getWindow(windowIndex, window, false).isDynamic) { } else if (timeline.getWindow(windowIndex, window, false).isDynamic) {
@ -1146,3 +1142,4 @@ public class PlaybackControlView extends FrameLayout {
} }
} }

View file

@ -250,6 +250,16 @@ public class FakeSimpleExoPlayer extends SimpleExoPlayer {
return 0; return 0;
} }
@Override
public int getNextWindowIndex() {
return C.INDEX_UNSET;
}
@Override
public int getPreviousWindowIndex() {
return C.INDEX_UNSET;
}
@Override @Override
public long getDuration() { public long getDuration() {
return C.usToMs(durationUs); return C.usToMs(durationUs);