Make TimelineQueueNavigator shuffle aware
Issue: #5065 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=220468285
This commit is contained in:
parent
b8b8844083
commit
fd98d70a11
@ -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
|
||||
|
@ -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;
|
||||
@ -68,6 +69,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
|
||||
this.mediaSession = mediaSession;
|
||||
this.maxQueueSize = maxQueueSize;
|
||||
activeQueueItemId = MediaSessionCompat.QueueItem.UNKNOWN_ID;
|
||||
window = new Timeline.Window();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,25 +83,24 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
|
||||
|
||||
@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;
|
||||
}
|
||||
return actions | PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM;
|
||||
if (window.isSeekable || !window.isDynamic || player.hasPrevious()) {
|
||||
actions |= PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS;
|
||||
}
|
||||
if (window.isDynamic || player.hasNext()) {
|
||||
actions |= PlaybackStateCompat.ACTION_SKIP_TO_NEXT;
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -125,22 +126,25 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
|
||||
@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;
|
||||
@ -152,12 +156,15 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -348,7 +348,7 @@ public final class ClippingMediaSource extends CompositeMediaSource<Void> {
|
||||
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) {
|
||||
|
@ -634,9 +634,8 @@ public class PlayerControlView extends FrameLayout {
|
||||
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);
|
||||
@ -831,7 +830,7 @@ public class PlayerControlView extends FrameLayout {
|
||||
|
||||
private void previous() {
|
||||
Timeline timeline = player.getCurrentTimeline();
|
||||
if (timeline.isEmpty()) {
|
||||
if (timeline.isEmpty() || player.isPlayingAd()) {
|
||||
return;
|
||||
}
|
||||
int windowIndex = player.getCurrentWindowIndex();
|
||||
@ -848,14 +847,14 @@ public class PlayerControlView extends FrameLayout {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user