Add public SimpleExoPlayer methods to ExoPlayer.

PiperOrigin-RevId: 401535981
This commit is contained in:
samrobinson 2021-10-07 17:45:22 +01:00 committed by bachinger
parent fc25798af6
commit 96a2c03f59
4 changed files with 175 additions and 70 deletions

View File

@ -7,6 +7,9 @@
level >= 31. Add methods in `DefaultMediaCodecRendererFactory` and level >= 31. Add methods in `DefaultMediaCodecRendererFactory` and
`DefaultRenderersFactory` to force enable or force disable asynchronous `DefaultRenderersFactory` to force enable or force disable asynchronous
queueing ([6348](https://github.com/google/ExoPlayer/issues/6348)). 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 * Move `com.google.android.exoplayer2.device.DeviceInfo` to
`com.google.android.exoplayer2.DeviceInfo`. `com.google.android.exoplayer2.DeviceInfo`.
* Move `com.google.android.exoplayer2.drm.DecryptionException` to * Move `com.google.android.exoplayer2.drm.DecryptionException` to

View File

@ -27,6 +27,7 @@ import androidx.annotation.IntRange;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import com.google.android.exoplayer2.analytics.AnalyticsCollector; 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.AudioAttributes;
import com.google.android.exoplayer2.audio.AudioCapabilities; import com.google.android.exoplayer2.audio.AudioCapabilities;
import com.google.android.exoplayer2.audio.AudioSink; import com.google.android.exoplayer2.audio.AudioSink;
@ -943,6 +944,23 @@ public interface ExoPlayer extends Player {
*/ */
void removeAudioOffloadListener(AudioOffloadListener listener); 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. */ /** Returns the number of renderers. */
int getRendererCount(); int getRendererCount();
@ -1268,6 +1286,77 @@ public interface ExoPlayer extends Player {
*/ */
boolean getPauseAtEndOfMediaItems(); 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 <a
* href="https://developer.android.com/guide/topics/media-apps/volume-and-earphones#becoming-noisy">audio
* becoming noisy</a> 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.
*
* <p>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).
*
* <p>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.
*
* <p>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()}.
*
* <p>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 * 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. * rarely as possible when playing an audio stream using audio offload.

View File

@ -906,41 +906,25 @@ public class SimpleExoPlayer extends BasePlayer
notifySkipSilenceEnabledChanged(); notifySkipSilenceEnabledChanged();
} }
/** Returns the {@link AnalyticsCollector} used for collecting analytics events. */ @Override
public AnalyticsCollector getAnalyticsCollector() { public AnalyticsCollector getAnalyticsCollector() {
return analyticsCollector; return analyticsCollector;
} }
/** @Override
* Adds an {@link AnalyticsListener} to receive analytics events.
*
* @param listener The listener to be added.
*/
public void addAnalyticsListener(AnalyticsListener listener) { public void addAnalyticsListener(AnalyticsListener listener) {
// Don't verify application thread. We allow calls to this method from any thread. // Don't verify application thread. We allow calls to this method from any thread.
Assertions.checkNotNull(listener); Assertions.checkNotNull(listener);
analyticsCollector.addListener(listener); analyticsCollector.addListener(listener);
} }
/** @Override
* Removes an {@link AnalyticsListener}.
*
* @param listener The listener to be removed.
*/
public void removeAnalyticsListener(AnalyticsListener listener) { public void removeAnalyticsListener(AnalyticsListener listener) {
// Don't verify application thread. We allow calls to this method from any thread. // Don't verify application thread. We allow calls to this method from any thread.
analyticsCollector.removeListener(listener); analyticsCollector.removeListener(listener);
} }
/** @Override
* Sets whether the player should pause automatically when audio is rerouted from a headset to
* device speakers. See the <a
* href="https://developer.android.com/guide/topics/media-apps/volume-and-earphones#becoming-noisy">audio
* becoming noisy</a> documentation for more information.
*
* @param handleAudioBecomingNoisy Whether the player should pause automatically when audio is
* rerouted from a headset to device speakers.
*/
public void setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy) { public void setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy) {
verifyApplicationThread(); verifyApplicationThread();
if (playerReleased) { if (playerReleased) {
@ -949,14 +933,7 @@ public class SimpleExoPlayer extends BasePlayer
audioBecomingNoisyManager.setEnabled(handleAudioBecomingNoisy); audioBecomingNoisyManager.setEnabled(handleAudioBecomingNoisy);
} }
/** @Override
* Sets a {@link PriorityTaskManager}, or null to clear a previously set priority task manager.
*
* <p>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.
*/
public void setPriorityTaskManager(@Nullable PriorityTaskManager priorityTaskManager) { public void setPriorityTaskManager(@Nullable PriorityTaskManager priorityTaskManager) {
verifyApplicationThread(); verifyApplicationThread();
if (Util.areEqual(this.priorityTaskManager, priorityTaskManager)) { if (Util.areEqual(this.priorityTaskManager, priorityTaskManager)) {
@ -974,25 +951,25 @@ public class SimpleExoPlayer extends BasePlayer
this.priorityTaskManager = priorityTaskManager; this.priorityTaskManager = priorityTaskManager;
} }
/** Returns the video format currently being played, or null if no video is being played. */ @Override
@Nullable @Nullable
public Format getVideoFormat() { public Format getVideoFormat() {
return videoFormat; return videoFormat;
} }
/** Returns the audio format currently being played, or null if no audio is being played. */ @Override
@Nullable @Nullable
public Format getAudioFormat() { public Format getAudioFormat() {
return audioFormat; return audioFormat;
} }
/** Returns {@link DecoderCounters} for video, or null if no video is being played. */ @Override
@Nullable @Nullable
public DecoderCounters getVideoDecoderCounters() { public DecoderCounters getVideoDecoderCounters() {
return videoDecoderCounters; return videoDecoderCounters;
} }
/** Returns {@link DecoderCounters} for audio, or null if no audio is being played. */ @Override
@Nullable @Nullable
public DecoderCounters getAudioDecoderCounters() { public DecoderCounters getAudioDecoderCounters() {
return audioDecoderCounters; return audioDecoderCounters;
@ -1561,39 +1538,13 @@ public class SimpleExoPlayer extends BasePlayer
return player.getContentBufferedPosition(); 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.
*
* <p>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 @Deprecated
@Override
public void setHandleWakeLock(boolean handleWakeLock) { public void setHandleWakeLock(boolean handleWakeLock) {
setWakeMode(handleWakeLock ? C.WAKE_MODE_LOCAL : C.WAKE_MODE_NONE); setWakeMode(handleWakeLock ? C.WAKE_MODE_LOCAL : C.WAKE_MODE_NONE);
} }
/** @Override
* Sets how the player should keep the device awake for playback when the screen is off.
*
* <p>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).
*
* <p>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.
*/
public void setWakeMode(@C.WakeMode int wakeMode) { public void setWakeMode(@C.WakeMode int wakeMode) {
verifyApplicationThread(); verifyApplicationThread();
switch (wakeMode) { switch (wakeMode) {
@ -1656,17 +1607,8 @@ public class SimpleExoPlayer extends BasePlayer
streamVolumeManager.setMuted(muted); 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()}.
*
* <p>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 @Deprecated
@Override
public void setThrowsWhenUsingWrongThread(boolean throwsWhenUsingWrongThread) { public void setThrowsWhenUsingWrongThread(boolean throwsWhenUsingWrongThread) {
this.throwsWhenUsingWrongThread = throwsWhenUsingWrongThread; this.throwsWhenUsingWrongThread = throwsWhenUsingWrongThread;
} }

View File

@ -26,6 +26,7 @@ import com.google.android.exoplayer2.BasePlayer;
import com.google.android.exoplayer2.DeviceInfo; import com.google.android.exoplayer2.DeviceInfo;
import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.MediaMetadata; import com.google.android.exoplayer2.MediaMetadata;
import com.google.android.exoplayer2.PlaybackParameters; 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.SeekParameters;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.TracksInfo; 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.AudioAttributes;
import com.google.android.exoplayer2.audio.AuxEffectInfo; 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.MediaSource;
import com.google.android.exoplayer2.source.ShuffleOrder; import com.google.android.exoplayer2.source.ShuffleOrder;
import com.google.android.exoplayer2.source.TrackGroupArray; 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.TrackSelectionParameters;
import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.util.Clock; 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.VideoFrameMetadataListener;
import com.google.android.exoplayer2.video.VideoSize; import com.google.android.exoplayer2.video.VideoSize;
import com.google.android.exoplayer2.video.spherical.CameraMotionListener; import com.google.android.exoplayer2.video.spherical.CameraMotionListener;
@ -128,6 +133,21 @@ public class StubExoPlayer extends BasePlayer implements ExoPlayer {
throw new UnsupportedOperationException(); 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 @Override
@State @State
public int getPlaybackState() { public int getPlaybackState() {
@ -674,6 +694,57 @@ public class StubExoPlayer extends BasePlayer implements ExoPlayer {
throw new UnsupportedOperationException(); 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 @Override
public void experimentalSetOffloadSchedulingEnabled(boolean offloadSchedulingEnabled) { public void experimentalSetOffloadSchedulingEnabled(boolean offloadSchedulingEnabled) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();