mirror of
https://github.com/samsonjs/media.git
synced 2026-03-26 09:35:47 +00:00
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
This commit is contained in:
parent
2c8d5f846e
commit
bd81181892
8 changed files with 74 additions and 12 deletions
|
|
@ -371,6 +371,16 @@ public final class CastPlayer implements Player {
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNextWindowIndex() {
|
||||
return C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPreviousWindowIndex() {
|
||||
return C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDuration() {
|
||||
return currentTimeline.isEmpty() ? C.TIME_UNSET
|
||||
|
|
|
|||
|
|
@ -126,8 +126,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
|
|||
if (timeline.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int previousWindowIndex = timeline.getPreviousWindowIndex(player.getCurrentWindowIndex(),
|
||||
player.getRepeatMode(), false);
|
||||
int previousWindowIndex = player.getPreviousWindowIndex();
|
||||
if (player.getCurrentPosition() > MAX_POSITION_FOR_SEEK_TO_PREVIOUS
|
||||
|| previousWindowIndex == C.INDEX_UNSET) {
|
||||
player.seekTo(0);
|
||||
|
|
@ -154,8 +153,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
|
|||
if (timeline.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int nextWindowIndex = timeline.getNextWindowIndex(player.getCurrentWindowIndex(),
|
||||
player.getRepeatMode(), false);
|
||||
int nextWindowIndex = player.getNextWindowIndex();
|
||||
if (nextWindowIndex != C.INDEX_UNSET) {
|
||||
player.seekTo(nextWindowIndex, C.TIME_UNSET);
|
||||
}
|
||||
|
|
@ -186,3 +184,4 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -502,6 +502,16 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNextWindowIndex() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPreviousWindowIndex() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDuration() {
|
||||
throw new UnsupportedOperationException();
|
||||
|
|
|
|||
|
|
@ -317,6 +317,18 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNextWindowIndex() {
|
||||
return timeline.getNextWindowIndex(getCurrentWindowIndex(), getRepeatMode(),
|
||||
getShuffleModeEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPreviousWindowIndex() {
|
||||
return timeline.getPreviousWindowIndex(getCurrentWindowIndex(), getRepeatMode(),
|
||||
getShuffleModeEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDuration() {
|
||||
if (timeline.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -363,6 +363,20 @@ public interface Player {
|
|||
*/
|
||||
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
|
||||
* duration is not known.
|
||||
|
|
|
|||
|
|
@ -754,6 +754,16 @@ public class SimpleExoPlayer implements ExoPlayer {
|
|||
return player.getCurrentWindowIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNextWindowIndex() {
|
||||
return player.getNextWindowIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPreviousWindowIndex() {
|
||||
return player.getPreviousWindowIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDuration() {
|
||||
return player.getDuration();
|
||||
|
|
|
|||
|
|
@ -675,11 +675,8 @@ public class PlaybackControlView extends FrameLayout {
|
|||
timeline.getWindow(windowIndex, window);
|
||||
isSeekable = window.isSeekable;
|
||||
enablePrevious = isSeekable || !window.isDynamic
|
||||
|| timeline.getPreviousWindowIndex(windowIndex, player.getRepeatMode(), false)
|
||||
!= C.INDEX_UNSET;
|
||||
enableNext = window.isDynamic
|
||||
|| timeline.getNextWindowIndex(windowIndex, player.getRepeatMode(), false)
|
||||
!= C.INDEX_UNSET;
|
||||
|| player.getPreviousWindowIndex() != C.INDEX_UNSET;
|
||||
enableNext = window.isDynamic || player.getNextWindowIndex() != C.INDEX_UNSET;
|
||||
if (player.isPlayingAd()) {
|
||||
// Always hide player controls during ads.
|
||||
hide();
|
||||
|
|
@ -863,8 +860,7 @@ public class PlaybackControlView extends FrameLayout {
|
|||
}
|
||||
int windowIndex = player.getCurrentWindowIndex();
|
||||
timeline.getWindow(windowIndex, window);
|
||||
int previousWindowIndex = timeline.getPreviousWindowIndex(windowIndex, player.getRepeatMode(),
|
||||
false);
|
||||
int previousWindowIndex = player.getPreviousWindowIndex();
|
||||
if (previousWindowIndex != C.INDEX_UNSET
|
||||
&& (player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS
|
||||
|| (window.isDynamic && !window.isSeekable))) {
|
||||
|
|
@ -880,7 +876,7 @@ public class PlaybackControlView extends FrameLayout {
|
|||
return;
|
||||
}
|
||||
int windowIndex = player.getCurrentWindowIndex();
|
||||
int nextWindowIndex = timeline.getNextWindowIndex(windowIndex, player.getRepeatMode(), false);
|
||||
int nextWindowIndex = player.getNextWindowIndex();
|
||||
if (nextWindowIndex != C.INDEX_UNSET) {
|
||||
seekTo(nextWindowIndex, C.TIME_UNSET);
|
||||
} else if (timeline.getWindow(windowIndex, window, false).isDynamic) {
|
||||
|
|
@ -1146,3 +1142,4 @@ public class PlaybackControlView extends FrameLayout {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -250,6 +250,16 @@ public class FakeSimpleExoPlayer extends SimpleExoPlayer {
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNextWindowIndex() {
|
||||
return C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPreviousWindowIndex() {
|
||||
return C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDuration() {
|
||||
return C.usToMs(durationUs);
|
||||
|
|
|
|||
Loading…
Reference in a new issue