Commit bd811818 by tonihei Committed by Oliver Woodman

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
parent 2c8d5f84
......@@ -372,6 +372,16 @@ public final class CastPlayer implements Player {
}
@Override
public int getNextWindowIndex() {
return C.INDEX_UNSET;
}
@Override
public int getPreviousWindowIndex() {
return C.INDEX_UNSET;
}
@Override
public long getDuration() {
return currentTimeline.isEmpty() ? C.TIME_UNSET
: currentTimeline.getWindow(0, window).getDurationMs();
......
......@@ -126,8 +126,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
if (timeline.isEmpty()) {
return;
}
int previousWindowIndex = timeline.getPreviousWindowIndex(player.getCurrentWindowIndex(),
player.getRepeatMode(), false);
int previousWindowIndex = player.getPreviousWindowIndex();
if (player.getCurrentPosition() > MAX_POSITION_FOR_SEEK_TO_PREVIOUS
|| previousWindowIndex == C.INDEX_UNSET) {
player.seekTo(0);
......@@ -154,8 +153,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
if (timeline.isEmpty()) {
return;
}
int nextWindowIndex = timeline.getNextWindowIndex(player.getCurrentWindowIndex(),
player.getRepeatMode(), false);
int nextWindowIndex = player.getNextWindowIndex();
if (nextWindowIndex != C.INDEX_UNSET) {
player.seekTo(nextWindowIndex, C.TIME_UNSET);
}
......@@ -186,3 +184,4 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
}
}
......@@ -503,6 +503,16 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
}
@Override
public int getNextWindowIndex() {
throw new UnsupportedOperationException();
}
@Override
public int getPreviousWindowIndex() {
throw new UnsupportedOperationException();
}
@Override
public long getDuration() {
throw new UnsupportedOperationException();
}
......
......@@ -318,6 +318,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
public long getDuration() {
if (timeline.isEmpty()) {
return C.TIME_UNSET;
......
......@@ -364,6 +364,20 @@ public interface Player {
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
* duration is not known.
*/
......
......@@ -755,6 +755,16 @@ public class SimpleExoPlayer implements ExoPlayer {
}
@Override
public int getNextWindowIndex() {
return player.getNextWindowIndex();
}
@Override
public int getPreviousWindowIndex() {
return player.getPreviousWindowIndex();
}
@Override
public long getDuration() {
return player.getDuration();
}
......
......@@ -675,11 +675,8 @@ public class PlaybackControlView extends FrameLayout {
timeline.getWindow(windowIndex, window);
isSeekable = window.isSeekable;
enablePrevious = isSeekable || !window.isDynamic
|| timeline.getPreviousWindowIndex(windowIndex, player.getRepeatMode(), false)
!= C.INDEX_UNSET;
enableNext = window.isDynamic
|| timeline.getNextWindowIndex(windowIndex, player.getRepeatMode(), false)
!= C.INDEX_UNSET;
|| player.getPreviousWindowIndex() != C.INDEX_UNSET;
enableNext = window.isDynamic || player.getNextWindowIndex() != C.INDEX_UNSET;
if (player.isPlayingAd()) {
// Always hide player controls during ads.
hide();
......@@ -863,8 +860,7 @@ public class PlaybackControlView extends FrameLayout {
}
int windowIndex = player.getCurrentWindowIndex();
timeline.getWindow(windowIndex, window);
int previousWindowIndex = timeline.getPreviousWindowIndex(windowIndex, player.getRepeatMode(),
false);
int previousWindowIndex = player.getPreviousWindowIndex();
if (previousWindowIndex != C.INDEX_UNSET
&& (player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS
|| (window.isDynamic && !window.isSeekable))) {
......@@ -880,7 +876,7 @@ public class PlaybackControlView extends FrameLayout {
return;
}
int windowIndex = player.getCurrentWindowIndex();
int nextWindowIndex = timeline.getNextWindowIndex(windowIndex, player.getRepeatMode(), false);
int nextWindowIndex = player.getNextWindowIndex();
if (nextWindowIndex != C.INDEX_UNSET) {
seekTo(nextWindowIndex, C.TIME_UNSET);
} else if (timeline.getWindow(windowIndex, window, false).isDynamic) {
......@@ -1146,3 +1142,4 @@ public class PlaybackControlView extends FrameLayout {
}
}
......@@ -251,6 +251,16 @@ public class FakeSimpleExoPlayer extends SimpleExoPlayer {
}
@Override
public int getNextWindowIndex() {
return C.INDEX_UNSET;
}
@Override
public int getPreviousWindowIndex() {
return C.INDEX_UNSET;
}
@Override
public long getDuration() {
return C.usToMs(durationUs);
}
......
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