Add convenience methods player.next() and player.previous()
This simplifies code skipping items in a playlist programatically. Issue:#4863 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=214580742
This commit is contained in:
parent
bbd82cf5da
commit
e4c20aa3de
@ -2,11 +2,14 @@
|
||||
|
||||
### 2.9.1 ###
|
||||
|
||||
* Add convenience methods `Player.next`, `Player.previous`, `Player.hasNext`
|
||||
and `Player.hasPrevious`
|
||||
([#4863](https://github.com/google/ExoPlayer/issues/4863)).
|
||||
* Improve initial bandwidth meter estimates using the current country and
|
||||
network type.
|
||||
* IMA extension:
|
||||
* For preroll to live stream transitions, project forward the
|
||||
loading position to avoid being behind the live window.
|
||||
* For preroll to live stream transitions, project forward the loading position
|
||||
to avoid being behind the live window.
|
||||
* Let apps specify whether to focus the skip button on ATV
|
||||
([#5019](https://github.com/google/ExoPlayer/issues/5019)).
|
||||
* MP3:
|
||||
|
@ -365,6 +365,32 @@ public final class CastPlayer extends BasePlayer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return getPreviousWindowIndex() != C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void previous() {
|
||||
int previousWindowIndex = getPreviousWindowIndex();
|
||||
if (previousWindowIndex != C.INDEX_UNSET) {
|
||||
seekToDefaultPosition(previousWindowIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return getNextWindowIndex() != C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void next() {
|
||||
int nextWindowIndex = getPreviousWindowIndex();
|
||||
if (nextWindowIndex != C.INDEX_UNSET) {
|
||||
seekToDefaultPosition(nextWindowIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlaybackParameters(@Nullable PlaybackParameters playbackParameters) {
|
||||
// Unsupported by the RemoteMediaClient API. Do nothing.
|
||||
|
@ -329,6 +329,32 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return getPreviousWindowIndex() != C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void previous() {
|
||||
int previousWindowIndex = getPreviousWindowIndex();
|
||||
if (previousWindowIndex != C.INDEX_UNSET) {
|
||||
seekToDefaultPosition(previousWindowIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return getNextWindowIndex() != C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void next() {
|
||||
int nextWindowIndex = getPreviousWindowIndex();
|
||||
if (nextWindowIndex != C.INDEX_UNSET) {
|
||||
seekToDefaultPosition(nextWindowIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlaybackParameters(@Nullable PlaybackParameters playbackParameters) {
|
||||
if (playbackParameters == null) {
|
||||
|
@ -659,6 +659,32 @@ public interface Player {
|
||||
*/
|
||||
void seekTo(int windowIndex, long positionMs);
|
||||
|
||||
/**
|
||||
* Returns whether a previous window exists, which may depend on the current repeat mode and
|
||||
* whether shuffle mode is enabled.
|
||||
*/
|
||||
boolean hasPrevious();
|
||||
|
||||
/**
|
||||
* Seeks to the default position of the previous window in the timeline, which may depend on the
|
||||
* current repeat mode and whether shuffle mode is enabled. Does nothing if {@link #hasPrevious()}
|
||||
* is {@code false}.
|
||||
*/
|
||||
void previous();
|
||||
|
||||
/**
|
||||
* Returns whether a next window exists, which may depend on the current repeat mode and whether
|
||||
* shuffle mode is enabled.
|
||||
*/
|
||||
boolean hasNext();
|
||||
|
||||
/**
|
||||
* Seeks to the default position of the next window in the timeline, which may depend on the
|
||||
* current repeat mode and whether shuffle mode is enabled. Does nothing if {@link #hasNext()} is
|
||||
* {@code false}.
|
||||
*/
|
||||
void next();
|
||||
|
||||
/**
|
||||
* Attempts to set the playback parameters. Passing {@code null} sets the parameters to the
|
||||
* default, {@link PlaybackParameters#DEFAULT}, which means there is no speed or pitch adjustment.
|
||||
|
@ -934,6 +934,36 @@ public class SimpleExoPlayer extends BasePlayer
|
||||
player.seekTo(windowIndex, positionMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
verifyApplicationThread();
|
||||
return getPreviousWindowIndex() != C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void previous() {
|
||||
verifyApplicationThread();
|
||||
if (hasPrevious()) {
|
||||
analyticsCollector.notifySeekStarted();
|
||||
player.previous();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
verifyApplicationThread();
|
||||
return getNextWindowIndex() != C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void next() {
|
||||
verifyApplicationThread();
|
||||
if (hasNext()) {
|
||||
analyticsCollector.notifySeekStarted();
|
||||
player.next();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlaybackParameters(@Nullable PlaybackParameters playbackParameters) {
|
||||
verifyApplicationThread();
|
||||
|
@ -134,6 +134,26 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void previous() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void next() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlaybackParameters(PlaybackParameters playbackParameters) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
Loading…
x
Reference in New Issue
Block a user