From 96a2c03f59df2e8673f1c7fdc89fbbc9ad52486b Mon Sep 17 00:00:00 2001 From: samrobinson Date: Thu, 7 Oct 2021 17:45:22 +0100 Subject: [PATCH] Add public SimpleExoPlayer methods to ExoPlayer. PiperOrigin-RevId: 401535981 --- RELEASENOTES.md | 3 + .../google/android/exoplayer2/ExoPlayer.java | 89 +++++++++++++++++++ .../android/exoplayer2/SimpleExoPlayer.java | 82 +++-------------- .../exoplayer2/testutil/StubExoPlayer.java | 71 +++++++++++++++ 4 files changed, 175 insertions(+), 70 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 4dd7187546..81e25f90eb 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -7,6 +7,9 @@ level >= 31. Add methods in `DefaultMediaCodecRendererFactory` and `DefaultRenderersFactory` to force enable or force disable asynchronous queueing ([6348](https://github.com/google/ExoPlayer/issues/6348)). + * Add 12 public method headers to `ExoPlayer` that exist in + `SimpleExoPlayer`, such that all public methods in `SimpleExoPlayer` + are overrides. * Move `com.google.android.exoplayer2.device.DeviceInfo` to `com.google.android.exoplayer2.DeviceInfo`. * Move `com.google.android.exoplayer2.drm.DecryptionException` to diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java index b07113f69b..650317f32c 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java @@ -27,6 +27,7 @@ import androidx.annotation.IntRange; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import com.google.android.exoplayer2.analytics.AnalyticsCollector; +import com.google.android.exoplayer2.analytics.AnalyticsListener; import com.google.android.exoplayer2.audio.AudioAttributes; import com.google.android.exoplayer2.audio.AudioCapabilities; import com.google.android.exoplayer2.audio.AudioSink; @@ -943,6 +944,23 @@ public interface ExoPlayer extends Player { */ void removeAudioOffloadListener(AudioOffloadListener listener); + /** Returns the {@link AnalyticsCollector} used for collecting analytics events. */ + AnalyticsCollector getAnalyticsCollector(); + + /** + * Adds an {@link AnalyticsListener} to receive analytics events. + * + * @param listener The listener to be added. + */ + void addAnalyticsListener(AnalyticsListener listener); + + /** + * Removes an {@link AnalyticsListener}. + * + * @param listener The listener to be removed. + */ + void removeAnalyticsListener(AnalyticsListener listener); + /** Returns the number of renderers. */ int getRendererCount(); @@ -1268,6 +1286,77 @@ public interface ExoPlayer extends Player { */ boolean getPauseAtEndOfMediaItems(); + /** Returns the audio format currently being played, or null if no audio is being played. */ + @Nullable + Format getAudioFormat(); + + /** Returns the video format currently being played, or null if no video is being played. */ + @Nullable + Format getVideoFormat(); + + /** Returns {@link DecoderCounters} for audio, or null if no audio is being played. */ + @Nullable + DecoderCounters getAudioDecoderCounters(); + + /** Returns {@link DecoderCounters} for video, or null if no video is being played. */ + @Nullable + DecoderCounters getVideoDecoderCounters(); + + /** + * Sets whether the player should pause automatically when audio is rerouted from a headset to + * device speakers. See the audio + * becoming noisy documentation for more information. + * + * @param handleAudioBecomingNoisy Whether the player should pause automatically when audio is + * rerouted from a headset to device speakers. + */ + void setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy); + + /** @deprecated Use {@link #setWakeMode(int)} instead. */ + @Deprecated + void setHandleWakeLock(boolean handleWakeLock); + + /** + * Sets how the player should keep the device awake for playback when the screen is off. + * + *

Enabling this feature requires the {@link android.Manifest.permission#WAKE_LOCK} permission. + * It should be used together with a foreground {@link android.app.Service} for use cases where + * playback occurs and the screen is off (e.g. background audio playback). It is not useful when + * the screen will be kept on during playback (e.g. foreground video playback). + * + *

When enabled, the locks ({@link android.os.PowerManager.WakeLock} / {@link + * android.net.wifi.WifiManager.WifiLock}) will be held whenever the player is in the {@link + * #STATE_READY} or {@link #STATE_BUFFERING} states with {@code playWhenReady = true}. The locks + * held depends on the specified {@link C.WakeMode}. + * + * @param wakeMode The {@link C.WakeMode} option to keep the device awake during playback. + */ + void setWakeMode(@C.WakeMode int wakeMode); + + /** + * Sets a {@link PriorityTaskManager}, or null to clear a previously set priority task manager. + * + *

The priority {@link C#PRIORITY_PLAYBACK} will be set while the player is loading. + * + * @param priorityTaskManager The {@link PriorityTaskManager}, or null to clear a previously set + * priority task manager. + */ + void setPriorityTaskManager(@Nullable PriorityTaskManager priorityTaskManager); + + /** + * Sets whether the player should throw an {@link IllegalStateException} when methods are called + * from a thread other than the one associated with {@link #getApplicationLooper()}. + * + *

The default is {@code true} and this method will be removed in the future. + * + * @param throwsWhenUsingWrongThread Whether to throw when methods are called from a wrong thread. + * @deprecated Disabling the enforcement can result in hard-to-detect bugs. Do not use this method + * except to ease the transition while wrong thread access problems are fixed. + */ + @Deprecated + void setThrowsWhenUsingWrongThread(boolean throwsWhenUsingWrongThread); + /** * Sets whether audio offload scheduling is enabled. If enabled, ExoPlayer's main loop will run as * rarely as possible when playing an audio stream using audio offload. diff --git a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java index 589b196531..11f09cf9c4 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java @@ -906,41 +906,25 @@ public class SimpleExoPlayer extends BasePlayer notifySkipSilenceEnabledChanged(); } - /** Returns the {@link AnalyticsCollector} used for collecting analytics events. */ + @Override public AnalyticsCollector getAnalyticsCollector() { return analyticsCollector; } - /** - * Adds an {@link AnalyticsListener} to receive analytics events. - * - * @param listener The listener to be added. - */ + @Override public void addAnalyticsListener(AnalyticsListener listener) { // Don't verify application thread. We allow calls to this method from any thread. Assertions.checkNotNull(listener); analyticsCollector.addListener(listener); } - /** - * Removes an {@link AnalyticsListener}. - * - * @param listener The listener to be removed. - */ + @Override public void removeAnalyticsListener(AnalyticsListener listener) { // Don't verify application thread. We allow calls to this method from any thread. analyticsCollector.removeListener(listener); } - /** - * Sets whether the player should pause automatically when audio is rerouted from a headset to - * device speakers. See the audio - * becoming noisy documentation for more information. - * - * @param handleAudioBecomingNoisy Whether the player should pause automatically when audio is - * rerouted from a headset to device speakers. - */ + @Override public void setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy) { verifyApplicationThread(); if (playerReleased) { @@ -949,14 +933,7 @@ public class SimpleExoPlayer extends BasePlayer audioBecomingNoisyManager.setEnabled(handleAudioBecomingNoisy); } - /** - * Sets a {@link PriorityTaskManager}, or null to clear a previously set priority task manager. - * - *

The priority {@link C#PRIORITY_PLAYBACK} will be set while the player is loading. - * - * @param priorityTaskManager The {@link PriorityTaskManager}, or null to clear a previously set - * priority task manager. - */ + @Override public void setPriorityTaskManager(@Nullable PriorityTaskManager priorityTaskManager) { verifyApplicationThread(); if (Util.areEqual(this.priorityTaskManager, priorityTaskManager)) { @@ -974,25 +951,25 @@ public class SimpleExoPlayer extends BasePlayer this.priorityTaskManager = priorityTaskManager; } - /** Returns the video format currently being played, or null if no video is being played. */ + @Override @Nullable public Format getVideoFormat() { return videoFormat; } - /** Returns the audio format currently being played, or null if no audio is being played. */ + @Override @Nullable public Format getAudioFormat() { return audioFormat; } - /** Returns {@link DecoderCounters} for video, or null if no video is being played. */ + @Override @Nullable public DecoderCounters getVideoDecoderCounters() { return videoDecoderCounters; } - /** Returns {@link DecoderCounters} for audio, or null if no audio is being played. */ + @Override @Nullable public DecoderCounters getAudioDecoderCounters() { return audioDecoderCounters; @@ -1561,39 +1538,13 @@ public class SimpleExoPlayer extends BasePlayer return player.getContentBufferedPosition(); } - /** - * Sets whether the player should use a {@link android.os.PowerManager.WakeLock} to ensure the - * device stays awake for playback, even when the screen is off. - * - *

Enabling this feature requires the {@link android.Manifest.permission#WAKE_LOCK} permission. - * It should be used together with a foreground {@link android.app.Service} for use cases where - * playback can occur when the screen is off (e.g. background audio playback). It is not useful if - * the screen will always be on during playback (e.g. foreground video playback). - * - * @param handleWakeLock Whether the player should use a {@link android.os.PowerManager.WakeLock} - * to ensure the device stays awake for playback, even when the screen is off. - * @deprecated Use {@link #setWakeMode(int)} instead. - */ @Deprecated + @Override public void setHandleWakeLock(boolean handleWakeLock) { setWakeMode(handleWakeLock ? C.WAKE_MODE_LOCAL : C.WAKE_MODE_NONE); } - /** - * Sets how the player should keep the device awake for playback when the screen is off. - * - *

Enabling this feature requires the {@link android.Manifest.permission#WAKE_LOCK} permission. - * It should be used together with a foreground {@link android.app.Service} for use cases where - * playback occurs and the screen is off (e.g. background audio playback). It is not useful when - * the screen will be kept on during playback (e.g. foreground video playback). - * - *

When enabled, the locks ({@link android.os.PowerManager.WakeLock} / {@link - * android.net.wifi.WifiManager.WifiLock}) will be held whenever the player is in the {@link - * #STATE_READY} or {@link #STATE_BUFFERING} states with {@code playWhenReady = true}. The locks - * held depends on the specified {@link C.WakeMode}. - * - * @param wakeMode The {@link C.WakeMode} option to keep the device awake during playback. - */ + @Override public void setWakeMode(@C.WakeMode int wakeMode) { verifyApplicationThread(); switch (wakeMode) { @@ -1656,17 +1607,8 @@ public class SimpleExoPlayer extends BasePlayer streamVolumeManager.setMuted(muted); } - /** - * Sets whether the player should throw an {@link IllegalStateException} when methods are called - * from a thread other than the one associated with {@link #getApplicationLooper()}. - * - *

The default is {@code true} and this method will be removed in the future. - * - * @param throwsWhenUsingWrongThread Whether to throw when methods are called from a wrong thread. - * @deprecated Disabling the enforcement can result in hard-to-detect bugs. Do not use this method - * except to ease the transition while wrong thread access problems are fixed. - */ @Deprecated + @Override public void setThrowsWhenUsingWrongThread(boolean throwsWhenUsingWrongThread) { this.throwsWhenUsingWrongThread = throwsWhenUsingWrongThread; } diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java index f46e394d38..eeb4c5856a 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java @@ -26,6 +26,7 @@ import com.google.android.exoplayer2.BasePlayer; import com.google.android.exoplayer2.DeviceInfo; import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.ExoPlayer; +import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.MediaMetadata; import com.google.android.exoplayer2.PlaybackParameters; @@ -34,8 +35,11 @@ import com.google.android.exoplayer2.PlayerMessage; import com.google.android.exoplayer2.SeekParameters; import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.TracksInfo; +import com.google.android.exoplayer2.analytics.AnalyticsCollector; +import com.google.android.exoplayer2.analytics.AnalyticsListener; import com.google.android.exoplayer2.audio.AudioAttributes; import com.google.android.exoplayer2.audio.AuxEffectInfo; +import com.google.android.exoplayer2.decoder.DecoderCounters; import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.ShuffleOrder; import com.google.android.exoplayer2.source.TrackGroupArray; @@ -44,6 +48,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelectionParameters; import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.util.Clock; +import com.google.android.exoplayer2.util.PriorityTaskManager; import com.google.android.exoplayer2.video.VideoFrameMetadataListener; import com.google.android.exoplayer2.video.VideoSize; import com.google.android.exoplayer2.video.spherical.CameraMotionListener; @@ -128,6 +133,21 @@ public class StubExoPlayer extends BasePlayer implements ExoPlayer { throw new UnsupportedOperationException(); } + @Override + public AnalyticsCollector getAnalyticsCollector() { + throw new UnsupportedOperationException(); + } + + @Override + public void addAnalyticsListener(AnalyticsListener listener) { + throw new UnsupportedOperationException(); + } + + @Override + public void removeAnalyticsListener(AnalyticsListener listener) { + throw new UnsupportedOperationException(); + } + @Override @State public int getPlaybackState() { @@ -674,6 +694,57 @@ public class StubExoPlayer extends BasePlayer implements ExoPlayer { throw new UnsupportedOperationException(); } + @Nullable + @Override + public Format getAudioFormat() { + throw new UnsupportedOperationException(); + } + + @Nullable + @Override + public Format getVideoFormat() { + throw new UnsupportedOperationException(); + } + + @Nullable + @Override + public DecoderCounters getAudioDecoderCounters() { + throw new UnsupportedOperationException(); + } + + @Nullable + @Override + public DecoderCounters getVideoDecoderCounters() { + throw new UnsupportedOperationException(); + } + + @Override + public void setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy) { + throw new UnsupportedOperationException(); + } + + @Deprecated + @Override + public void setHandleWakeLock(boolean handleWakeLock) { + throw new UnsupportedOperationException(); + } + + @Override + public void setWakeMode(int wakeMode) { + throw new UnsupportedOperationException(); + } + + @Override + public void setPriorityTaskManager(@Nullable PriorityTaskManager priorityTaskManager) { + throw new UnsupportedOperationException(); + } + + @Deprecated + @Override + public void setThrowsWhenUsingWrongThread(boolean throwsWhenUsingWrongThread) { + throw new UnsupportedOperationException(); + } + @Override public void experimentalSetOffloadSchedulingEnabled(boolean offloadSchedulingEnabled) { throw new UnsupportedOperationException();