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 { ...@@ -372,6 +372,16 @@ public final class CastPlayer implements Player {
} }
@Override @Override
public int getNextWindowIndex() {
return C.INDEX_UNSET;
}
@Override
public int getPreviousWindowIndex() {
return C.INDEX_UNSET;
}
@Override
public long getDuration() { public long getDuration() {
return currentTimeline.isEmpty() ? C.TIME_UNSET return currentTimeline.isEmpty() ? C.TIME_UNSET
: currentTimeline.getWindow(0, window).getDurationMs(); : currentTimeline.getWindow(0, window).getDurationMs();
......
...@@ -126,8 +126,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu ...@@ -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 ...@@ -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 ...@@ -186,3 +184,4 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
} }
} }
...@@ -503,6 +503,16 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase { ...@@ -503,6 +503,16 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
} }
@Override @Override
public int getNextWindowIndex() {
throw new UnsupportedOperationException();
}
@Override
public int getPreviousWindowIndex() {
throw new UnsupportedOperationException();
}
@Override
public long getDuration() { public long getDuration() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
......
...@@ -318,6 +318,18 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -318,6 +318,18 @@ import java.util.concurrent.CopyOnWriteArraySet;
} }
@Override @Override
public int getNextWindowIndex() {
return timeline.getNextWindowIndex(getCurrentWindowIndex(), getRepeatMode(),
getShuffleModeEnabled());
}
@Override
public int getPreviousWindowIndex() {
return timeline.getPreviousWindowIndex(getCurrentWindowIndex(), getRepeatMode(),
getShuffleModeEnabled());
}
@Override
public long getDuration() { public long getDuration() {
if (timeline.isEmpty()) { if (timeline.isEmpty()) {
return C.TIME_UNSET; return C.TIME_UNSET;
......
...@@ -364,6 +364,20 @@ public interface Player { ...@@ -364,6 +364,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.
*/ */
......
...@@ -755,6 +755,16 @@ public class SimpleExoPlayer implements ExoPlayer { ...@@ -755,6 +755,16 @@ public class SimpleExoPlayer implements ExoPlayer {
} }
@Override @Override
public int getNextWindowIndex() {
return player.getNextWindowIndex();
}
@Override
public int getPreviousWindowIndex() {
return player.getPreviousWindowIndex();
}
@Override
public long getDuration() { public long getDuration() {
return player.getDuration(); return player.getDuration();
} }
......
...@@ -675,11 +675,8 @@ public class PlaybackControlView extends FrameLayout { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -1146,3 +1142,4 @@ public class PlaybackControlView extends FrameLayout {
} }
} }
...@@ -251,6 +251,16 @@ public class FakeSimpleExoPlayer extends SimpleExoPlayer { ...@@ -251,6 +251,16 @@ public class FakeSimpleExoPlayer extends SimpleExoPlayer {
} }
@Override @Override
public int getNextWindowIndex() {
return C.INDEX_UNSET;
}
@Override
public int getPreviousWindowIndex() {
return C.INDEX_UNSET;
}
@Override
public long getDuration() { public long getDuration() {
return C.usToMs(durationUs); 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