Skip to content

Commit

Permalink
Make TimelineQueueNavigator shuffle aware
Browse files Browse the repository at this point in the history
Issue: #5065

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=220468285
  • Loading branch information
ojw28 committed Nov 7, 2018
1 parent b8b8844 commit fd98d70
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* Fix issue with blind seeking to windows with non-zero offset in a
`ConcatenatingMediaSource`
([#4873](https://github.com/google/ExoPlayer/issues/4873)).
* 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 it
([#5055](https://github.com/google/ExoPlayer/issues/5055)).
* Fix issue where subtitles were positioned incorrectly if `SubtitleView` had a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
public static final int DEFAULT_MAX_QUEUE_SIZE = 10;

private final MediaSessionCompat mediaSession;
private final Timeline.Window window;
protected final int maxQueueSize;

private long activeQueueItemId;
Expand Down Expand Up @@ -68,6 +69,7 @@ public TimelineQueueNavigator(MediaSessionCompat mediaSession, int maxQueueSize)
this.mediaSession = mediaSession;
this.maxQueueSize = maxQueueSize;
activeQueueItemId = MediaSessionCompat.QueueItem.UNKNOWN_ID;
window = new Timeline.Window();
}

/**
Expand All @@ -81,25 +83,24 @@ public TimelineQueueNavigator(MediaSessionCompat mediaSession, int maxQueueSize)

@Override
public long getSupportedQueueNavigatorActions(Player player) {
if (player == null || player.getCurrentTimeline().getWindowCount() < 2) {
if (player == null) {
return 0;
}
if (player.getRepeatMode() != Player.REPEAT_MODE_OFF) {
return PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
| PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM;
Timeline timeline = player.getCurrentTimeline();
if (timeline.isEmpty() || player.isPlayingAd()) {
return 0;
}

int currentWindowIndex = player.getCurrentWindowIndex();
long actions;
if (currentWindowIndex == 0) {
actions = PlaybackStateCompat.ACTION_SKIP_TO_NEXT;
} else if (currentWindowIndex == player.getCurrentTimeline().getWindowCount() - 1) {
actions = PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS;
} else {
actions = PlaybackStateCompat.ACTION_SKIP_TO_NEXT
| PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS;
long actions = 0;
if (timeline.getWindowCount() > 1) {
actions |= PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM;
}
if (window.isSeekable || !window.isDynamic || player.hasPrevious()) {
actions |= 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
Expand All @@ -125,22 +126,25 @@ public final long getActiveQueueItemId(@Nullable Player player) {
@Override
public void onSkipToPrevious(Player player) {
Timeline timeline = player.getCurrentTimeline();
if (timeline.isEmpty()) {
if (timeline.isEmpty() || player.isPlayingAd()) {
return;
}
int windowIndex = player.getCurrentWindowIndex();
timeline.getWindow(windowIndex, window);
int previousWindowIndex = player.getPreviousWindowIndex();
if (player.getCurrentPosition() > MAX_POSITION_FOR_SEEK_TO_PREVIOUS
|| previousWindowIndex == C.INDEX_UNSET) {
player.seekTo(0);
} else {
if (previousWindowIndex != C.INDEX_UNSET
&& (player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS
|| (window.isDynamic && !window.isSeekable))) {
player.seekTo(previousWindowIndex, C.TIME_UNSET);
} else {
player.seekTo(0);
}
}

@Override
public void onSkipToQueueItem(Player player, long id) {
Timeline timeline = player.getCurrentTimeline();
if (timeline.isEmpty()) {
if (timeline.isEmpty() || player.isPlayingAd()) {
return;
}
int windowIndex = (int) id;
Expand All @@ -152,12 +156,15 @@ public void onSkipToQueueItem(Player player, long id) {
@Override
public void onSkipToNext(Player player) {
Timeline timeline = player.getCurrentTimeline();
if (timeline.isEmpty()) {
if (timeline.isEmpty() || player.isPlayingAd()) {
return;
}
int windowIndex = player.getCurrentWindowIndex();
int nextWindowIndex = player.getNextWindowIndex();
if (nextWindowIndex != C.INDEX_UNSET) {
player.seekTo(nextWindowIndex, C.TIME_UNSET);
} else if (timeline.getWindow(windowIndex, window).isDynamic) {
player.seekTo(windowIndex, C.TIME_UNSET);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public ClippingTimeline(Timeline timeline, long startUs, long endUs)
if (timeline.getPeriodCount() != 1) {
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);
long resolvedEndUs = endUs == C.TIME_END_OF_SOURCE ? window.durationUs : Math.max(0, endUs);
if (window.durationUs != C.TIME_UNSET) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,8 @@ private void updateNavigation() {
int windowIndex = player.getCurrentWindowIndex();
timeline.getWindow(windowIndex, window);
isSeekable = window.isSeekable;
enablePrevious =
isSeekable || !window.isDynamic || player.getPreviousWindowIndex() != C.INDEX_UNSET;
enableNext = window.isDynamic || player.getNextWindowIndex() != C.INDEX_UNSET;
enablePrevious = isSeekable || !window.isDynamic || player.hasPrevious();
enableNext = window.isDynamic || player.hasNext();
}
setButtonEnabled(enablePrevious, previousButton);
setButtonEnabled(enableNext, nextButton);
Expand Down Expand Up @@ -831,7 +830,7 @@ private void setButtonEnabled(boolean enabled, View view) {

private void previous() {
Timeline timeline = player.getCurrentTimeline();
if (timeline.isEmpty()) {
if (timeline.isEmpty() || player.isPlayingAd()) {
return;
}
int windowIndex = player.getCurrentWindowIndex();
Expand All @@ -848,14 +847,14 @@ private void previous() {

private void next() {
Timeline timeline = player.getCurrentTimeline();
if (timeline.isEmpty()) {
if (timeline.isEmpty() || player.isPlayingAd()) {
return;
}
int windowIndex = player.getCurrentWindowIndex();
int nextWindowIndex = player.getNextWindowIndex();
if (nextWindowIndex != C.INDEX_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);
}
}
Expand Down

0 comments on commit fd98d70

Please sign in to comment.