From b7666df2b3e80bb0005ae88b06ea745212d20573 Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 4 Dec 2019 14:24:19 +0000 Subject: [PATCH] Add Player play and pause convenience methods PiperOrigin-RevId: 283744017 --- RELEASENOTES.md | 1 + .../google/android/exoplayer2/BasePlayer.java | 10 +++++++++ .../com/google/android/exoplayer2/Player.java | 22 +++++++++++++------ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 3c6c46dbc5..f2b3a76081 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -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) ### diff --git a/library/core/src/main/java/com/google/android/exoplayer2/BasePlayer.java b/library/core/src/main/java/com/google/android/exoplayer2/BasePlayer.java index 2646cbc035..ab9e5f0e11 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/BasePlayer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/BasePlayer.java @@ -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 diff --git a/library/core/src/main/java/com/google/android/exoplayer2/Player.java b/library/core/src/main/java/com/google/android/exoplayer2/Player.java index a29851fefc..afcc8cf7c7 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/Player.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/Player.java @@ -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}. - *

- * If the player is already in the ready state then this method can be used to pause and resume - * playback. + * + *

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. * *

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. * *

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