Commit 15dda179 by olly Committed by Oliver Woodman

Make TimelineQueueNavigator shuffle aware

Issue: #5065

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=220468285
parent 2d606f26
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
### dev-v2 (not yet released) ### ### dev-v2 (not yet released) ###
* Fix logic for enabling next and previous actions in `TimelineQueueNavigator`
([#5065](https://github.com/google/ExoPlayer/issues/5065)).
* Fix issue where audio focus handling could not be disabled after enabling * Fix issue where audio focus handling could not be disabled after enabling
it ([#5055](https://github.com/google/ExoPlayer/issues/5055)). it ([#5055](https://github.com/google/ExoPlayer/issues/5055)).
* Support for playing spherical videos on Daydream. * Support for playing spherical videos on Daydream.
......
...@@ -39,6 +39,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu ...@@ -39,6 +39,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
public static final int DEFAULT_MAX_QUEUE_SIZE = 10; public static final int DEFAULT_MAX_QUEUE_SIZE = 10;
private final MediaSessionCompat mediaSession; private final MediaSessionCompat mediaSession;
private final Timeline.Window window;
protected final int maxQueueSize; protected final int maxQueueSize;
private long activeQueueItemId; private long activeQueueItemId;
...@@ -68,6 +69,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu ...@@ -68,6 +69,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
this.mediaSession = mediaSession; this.mediaSession = mediaSession;
this.maxQueueSize = maxQueueSize; this.maxQueueSize = maxQueueSize;
activeQueueItemId = MediaSessionCompat.QueueItem.UNKNOWN_ID; activeQueueItemId = MediaSessionCompat.QueueItem.UNKNOWN_ID;
window = new Timeline.Window();
} }
/** /**
...@@ -81,25 +83,24 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu ...@@ -81,25 +83,24 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
@Override @Override
public long getSupportedQueueNavigatorActions(Player player) { public long getSupportedQueueNavigatorActions(Player player) {
if (player == null || player.getCurrentTimeline().getWindowCount() < 2) { if (player == null) {
return 0; return 0;
} }
if (player.getRepeatMode() != Player.REPEAT_MODE_OFF) { Timeline timeline = player.getCurrentTimeline();
return PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS if (timeline.isEmpty() || player.isPlayingAd()) {
| PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM; return 0;
} }
long actions = 0;
int currentWindowIndex = player.getCurrentWindowIndex(); if (timeline.getWindowCount() > 1) {
long actions; actions |= PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM;
if (currentWindowIndex == 0) { }
actions = PlaybackStateCompat.ACTION_SKIP_TO_NEXT; if (window.isSeekable || !window.isDynamic || player.hasPrevious()) {
} else if (currentWindowIndex == player.getCurrentTimeline().getWindowCount() - 1) { actions |= PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS;
actions = PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS;
} else {
actions = PlaybackStateCompat.ACTION_SKIP_TO_NEXT
| PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS;
} }
return actions | PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM; if (window.isDynamic || player.hasNext()) {
actions |= PlaybackStateCompat.ACTION_SKIP_TO_NEXT;
}
return actions;
} }
@Override @Override
...@@ -125,22 +126,25 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu ...@@ -125,22 +126,25 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
@Override @Override
public void onSkipToPrevious(Player player) { public void onSkipToPrevious(Player player) {
Timeline timeline = player.getCurrentTimeline(); Timeline timeline = player.getCurrentTimeline();
if (timeline.isEmpty()) { if (timeline.isEmpty() || player.isPlayingAd()) {
return; return;
} }
int windowIndex = player.getCurrentWindowIndex();
timeline.getWindow(windowIndex, window);
int previousWindowIndex = player.getPreviousWindowIndex(); int previousWindowIndex = player.getPreviousWindowIndex();
if (player.getCurrentPosition() > MAX_POSITION_FOR_SEEK_TO_PREVIOUS if (previousWindowIndex != C.INDEX_UNSET
|| previousWindowIndex == C.INDEX_UNSET) { && (player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS
player.seekTo(0); || (window.isDynamic && !window.isSeekable))) {
} else {
player.seekTo(previousWindowIndex, C.TIME_UNSET); player.seekTo(previousWindowIndex, C.TIME_UNSET);
} else {
player.seekTo(0);
} }
} }
@Override @Override
public void onSkipToQueueItem(Player player, long id) { public void onSkipToQueueItem(Player player, long id) {
Timeline timeline = player.getCurrentTimeline(); Timeline timeline = player.getCurrentTimeline();
if (timeline.isEmpty()) { if (timeline.isEmpty() || player.isPlayingAd()) {
return; return;
} }
int windowIndex = (int) id; int windowIndex = (int) id;
...@@ -152,12 +156,15 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu ...@@ -152,12 +156,15 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
@Override @Override
public void onSkipToNext(Player player) { public void onSkipToNext(Player player) {
Timeline timeline = player.getCurrentTimeline(); Timeline timeline = player.getCurrentTimeline();
if (timeline.isEmpty()) { if (timeline.isEmpty() || player.isPlayingAd()) {
return; return;
} }
int windowIndex = player.getCurrentWindowIndex();
int nextWindowIndex = player.getNextWindowIndex(); int nextWindowIndex = player.getNextWindowIndex();
if (nextWindowIndex != C.INDEX_UNSET) { if (nextWindowIndex != C.INDEX_UNSET) {
player.seekTo(nextWindowIndex, C.TIME_UNSET); player.seekTo(nextWindowIndex, C.TIME_UNSET);
} else if (timeline.getWindow(windowIndex, window).isDynamic) {
player.seekTo(windowIndex, C.TIME_UNSET);
} }
} }
......
...@@ -318,7 +318,7 @@ public final class ClippingMediaSource extends CompositeMediaSource<Void> { ...@@ -318,7 +318,7 @@ public final class ClippingMediaSource extends CompositeMediaSource<Void> {
if (timeline.getPeriodCount() != 1) { if (timeline.getPeriodCount() != 1) {
throw new IllegalClippingException(IllegalClippingException.REASON_INVALID_PERIOD_COUNT); throw new IllegalClippingException(IllegalClippingException.REASON_INVALID_PERIOD_COUNT);
} }
Window window = timeline.getWindow(0, new Window(), false); Window window = timeline.getWindow(0, new Window());
startUs = Math.max(0, startUs); startUs = Math.max(0, startUs);
long resolvedEndUs = endUs == C.TIME_END_OF_SOURCE ? window.durationUs : Math.max(0, endUs); long resolvedEndUs = endUs == C.TIME_END_OF_SOURCE ? window.durationUs : Math.max(0, endUs);
if (window.durationUs != C.TIME_UNSET) { if (window.durationUs != C.TIME_UNSET) {
......
...@@ -668,9 +668,8 @@ public class PlayerControlView extends FrameLayout { ...@@ -668,9 +668,8 @@ public class PlayerControlView extends FrameLayout {
int windowIndex = player.getCurrentWindowIndex(); int windowIndex = player.getCurrentWindowIndex();
timeline.getWindow(windowIndex, window); timeline.getWindow(windowIndex, window);
isSeekable = window.isSeekable; isSeekable = window.isSeekable;
enablePrevious = enablePrevious = isSeekable || !window.isDynamic || player.hasPrevious();
isSeekable || !window.isDynamic || player.getPreviousWindowIndex() != C.INDEX_UNSET; enableNext = window.isDynamic || player.hasNext();
enableNext = window.isDynamic || player.getNextWindowIndex() != C.INDEX_UNSET;
} }
setButtonEnabled(enablePrevious, previousButton); setButtonEnabled(enablePrevious, previousButton);
setButtonEnabled(enableNext, nextButton); setButtonEnabled(enableNext, nextButton);
...@@ -865,7 +864,7 @@ public class PlayerControlView extends FrameLayout { ...@@ -865,7 +864,7 @@ public class PlayerControlView extends FrameLayout {
private void previous() { private void previous() {
Timeline timeline = player.getCurrentTimeline(); Timeline timeline = player.getCurrentTimeline();
if (timeline.isEmpty()) { if (timeline.isEmpty() || player.isPlayingAd()) {
return; return;
} }
int windowIndex = player.getCurrentWindowIndex(); int windowIndex = player.getCurrentWindowIndex();
...@@ -882,14 +881,14 @@ public class PlayerControlView extends FrameLayout { ...@@ -882,14 +881,14 @@ public class PlayerControlView extends FrameLayout {
private void next() { private void next() {
Timeline timeline = player.getCurrentTimeline(); Timeline timeline = player.getCurrentTimeline();
if (timeline.isEmpty()) { if (timeline.isEmpty() || player.isPlayingAd()) {
return; return;
} }
int windowIndex = player.getCurrentWindowIndex(); int windowIndex = player.getCurrentWindowIndex();
int nextWindowIndex = player.getNextWindowIndex(); 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).isDynamic) {
seekTo(windowIndex, C.TIME_UNSET); seekTo(windowIndex, C.TIME_UNSET);
} }
} }
......
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