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
|
* Fix issue with blind seeking to windows with non-zero offset in a
|
||||||
`ConcatenatingMediaSource`
|
`ConcatenatingMediaSource`
|
||||||
([#4873](https://github.com/google/ExoPlayer/issues/4873)).
|
([#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
|
* Fix issue where audio focus handling could not be disabled after enabling it
|
||||||
([#5055](https://github.com/google/ExoPlayer/issues/5055)).
|
([#5055](https://github.com/google/ExoPlayer/issues/5055)).
|
||||||
* Fix issue where subtitles were positioned incorrectly if `SubtitleView` had a
|
* 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;
|
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
|
|||||||
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
|
|||||||
|
|
||||||
@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;
|
|
||||||
} 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;
|
|
||||||
}
|
}
|
||||||
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
|
@Override
|
||||||
@ -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
|
|||||||
@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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,7 +348,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) {
|
||||||
|
@ -634,9 +634,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);
|
||||||
@ -831,7 +830,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();
|
||||||
@ -848,14 +847,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user