Add Player play and pause convenience methods

PiperOrigin-RevId: 283744017
This commit is contained in:
olly 2019-12-04 14:24:19 +00:00 committed by Ian Baker
parent e54b493bbf
commit b7666df2b3
3 changed files with 26 additions and 7 deletions

View file

@ -24,6 +24,7 @@
* Make media session connector dispatch ACTION_SET_CAPTIONING_ENABLED.
* Add support for position and overlapping start/end times in SSA/ASS subtitles
([#6320](https://github.com/google/ExoPlayer/issues/6320)).
* Add `play` and `pause` methods to `Player`.
* Upgrade Truth dependency from 0.44 to 1.0.
### 2.11.0 (not yet released) ###

View file

@ -27,6 +27,16 @@ public abstract class BasePlayer implements Player {
window = new Timeline.Window();
}
@Override
public final void play() {
setPlayWhenReady(true);
}
@Override
public final void pause() {
setPlayWhenReady(false);
}
@Override
public final boolean isPlaying() {
return getPlaybackState() == Player.STATE_READY

View file

@ -725,11 +725,19 @@ public interface Player {
@Nullable
ExoPlaybackException getPlaybackError();
/**
* Resumes playback as soon as {@link #getPlaybackState()} == {@link #STATE_READY}. Equivalent to
* {@code setPlayWhenReady(true)}.
*/
void play();
/** Pauses playback. Equivalent to {@code setPlayWhenReady(false)}. */
void pause();
/**
* Sets whether playback should proceed when {@link #getPlaybackState()} == {@link #STATE_READY}.
* <p>
* If the player is already in the ready state then this method can be used to pause and resume
* playback.
*
* <p>If the player is already in the ready state then this method pauses and resumes playback.
*
* @param playWhenReady Whether playback should proceed when ready.
*/
@ -857,8 +865,8 @@ public interface Player {
PlaybackParameters getPlaybackParameters();
/**
* Stops playback without resetting the player. Use {@code setPlayWhenReady(false)} rather than
* this method if the intention is to pause playback.
* Stops playback without resetting the player. Use {@link #pause()} rather than this method if
* the intention is to pause playback.
*
* <p>Calling this method will cause the playback state to transition to {@link #STATE_IDLE}. The
* player instance can still be used, and {@link #release()} must still be called on the player if
@ -869,8 +877,8 @@ public interface Player {
void stop();
/**
* Stops playback and optionally resets the player. Use {@code setPlayWhenReady(false)} rather
* than this method if the intention is to pause playback.
* Stops playback and optionally resets the player. Use {@link #pause()} rather than this method
* if the intention is to pause playback.
*
* <p>Calling this method will cause the playback state to transition to {@link #STATE_IDLE}. The
* player instance can still be used, and {@link #release()} must still be called on the player if