Add isReleased() to the Exoplayer

This avoids having to add AnalyticsListener and catching the `onPlayerReleased` callback.

The `Exoplayer.release()` method is blocking and one can be sure that the player is released if the call returned. However, the method is useful for UI testing and asserting that the player is released after a certain UI action, e.g. closing the activity or detaching a window.

PiperOrigin-RevId: 640114416
This commit is contained in:
jbibik 2024-06-04 05:08:09 -07:00 committed by Copybara-Service
parent 73dd743929
commit 35b8ab411d
5 changed files with 35 additions and 0 deletions

View File

@ -60,6 +60,8 @@
resulted in `Source Error` and `IllegalArgumentException`.
* Use data class for `LoadControl` methods instead of individual
parameters.
* Add `ExoPlayer.isReleased()` to check whether `Exoplayer.release()` has
been called.
* Transformer:
* Work around a decoder bug where the number of audio channels was capped
at stereo when handling PCM input.

View File

@ -1956,6 +1956,23 @@ public interface ExoPlayer extends Player {
@UnstableApi
boolean isTunnelingEnabled();
/**
* {@inheritDoc}
*
* <p>The exception to the above rule is {@link #isReleased()} which can be called on a released
* player.
*/
@Override
void release();
/**
* Returns whether {@link #release()} has been called on the player.
*
* <p>This method is allowed to be called after {@link #release()}.
*/
@UnstableApi
boolean isReleased();
/**
* Sets the {@link ImageOutput} where rendered images will be forwarded.
*

View File

@ -1105,6 +1105,12 @@ import java.util.concurrent.TimeoutException;
playerReleased = true;
}
@Override
public boolean isReleased() {
verifyApplicationThread();
return playerReleased;
}
@Override
public PlayerMessage createMessage(Target target) {
verifyApplicationThread();

View File

@ -1346,6 +1346,11 @@ public class SimpleExoPlayer extends BasePlayer
return player.isTunnelingEnabled();
}
@Override
public boolean isReleased() {
return player.isReleased();
}
@Override
public void setImageOutput(ImageOutput imageOutput) {
blockUntilConstructorFinished();

View File

@ -428,6 +428,11 @@ public class StubExoPlayer extends StubPlayer implements ExoPlayer {
throw new UnsupportedOperationException();
}
@Override
public boolean isReleased() {
throw new UnsupportedOperationException();
}
@Override
public void setImageOutput(ImageOutput imageOutput) {
throw new UnsupportedOperationException();