Add ExoPlayer.retry convenience method
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=211463309
This commit is contained in:
parent
7959a691ad
commit
c57fe1897c
@ -7,8 +7,9 @@
|
||||
`compileOptions { targetCompatibility JavaVersion.VERSION_1_8 }` to their
|
||||
gradle settings to ensure bytecode compatibility.
|
||||
* Set `compileSdkVersion` and `targetSdkVersion` to 28.
|
||||
* Added support for automatic audio focus handling via
|
||||
* Support for automatic audio focus handling via
|
||||
`SimpleExoPlayer.setAudioAttributes`.
|
||||
* Added `ExoPlayer.retry` convenience method.
|
||||
* Add `AudioListener` for listening to changes in audio configuration during
|
||||
playback ([#3994](https://github.com/google/ExoPlayer/issues/3994)).
|
||||
* Add `LoadErrorHandlingPolicy` to allow configuration of load error handling
|
||||
|
@ -188,6 +188,12 @@ public interface ExoPlayer extends Player {
|
||||
*/
|
||||
Looper getApplicationLooper();
|
||||
|
||||
/**
|
||||
* Retries a failed or stopped playback. Does nothing if the player has been reset, or if playback
|
||||
* has not failed or been stopped.
|
||||
*/
|
||||
void retry();
|
||||
|
||||
/**
|
||||
* Prepares the player to play the provided {@link MediaSource}. Equivalent to
|
||||
* {@code prepare(mediaSource, true, true)}.
|
||||
|
@ -65,6 +65,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
private final Timeline.Period period;
|
||||
private final ArrayDeque<PlaybackInfoUpdate> pendingPlaybackInfoUpdates;
|
||||
|
||||
private MediaSource mediaSource;
|
||||
private boolean playWhenReady;
|
||||
private boolean internalPlayWhenReady;
|
||||
private @RepeatMode int repeatMode;
|
||||
@ -191,14 +192,23 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
return playbackError;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retry() {
|
||||
if (mediaSource != null
|
||||
&& (playbackError != null || playbackInfo.playbackState == Player.STATE_IDLE)) {
|
||||
prepare(mediaSource, /* resetPosition= */ false, /* resetState= */ false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(MediaSource mediaSource) {
|
||||
prepare(mediaSource, true, true);
|
||||
prepare(mediaSource, /* resetPosition= */ true, /* resetState= */ true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(MediaSource mediaSource, boolean resetPosition, boolean resetState) {
|
||||
playbackError = null;
|
||||
this.mediaSource = mediaSource;
|
||||
PlaybackInfo playbackInfo =
|
||||
getResetPlaybackInfo(
|
||||
resetPosition, resetState, /* playbackState= */ Player.STATE_BUFFERING);
|
||||
@ -384,6 +394,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
public void stop(boolean reset) {
|
||||
if (reset) {
|
||||
playbackError = null;
|
||||
mediaSource = null;
|
||||
}
|
||||
PlaybackInfo playbackInfo =
|
||||
getResetPlaybackInfo(
|
||||
@ -410,6 +421,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
Log.i(TAG, "Release " + Integer.toHexString(System.identityHashCode(this)) + " ["
|
||||
+ ExoPlayerLibraryInfo.VERSION_SLASHY + "] [" + Util.DEVICE_DEBUG_INFO + "] ["
|
||||
+ ExoPlayerLibraryInfo.registeredModules() + "]");
|
||||
mediaSource = null;
|
||||
internalPlayer.release();
|
||||
eventHandler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
@ -832,6 +832,14 @@ public class SimpleExoPlayer
|
||||
return player.getPlaybackError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retry() {
|
||||
if (mediaSource != null
|
||||
&& (getPlaybackError() != null || getPlaybackState() == Player.STATE_IDLE)) {
|
||||
prepare(mediaSource, /* resetPosition= */ false, /* resetState= */ false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(MediaSource mediaSource) {
|
||||
prepare(mediaSource, /* resetPosition= */ true, /* resetState= */ true);
|
||||
@ -839,14 +847,12 @@ public class SimpleExoPlayer
|
||||
|
||||
@Override
|
||||
public void prepare(MediaSource mediaSource, boolean resetPosition, boolean resetState) {
|
||||
if (this.mediaSource != mediaSource) {
|
||||
if (this.mediaSource != null) {
|
||||
this.mediaSource.removeEventListener(analyticsCollector);
|
||||
analyticsCollector.resetForNewMediaSource();
|
||||
}
|
||||
mediaSource.addEventListener(eventHandler, analyticsCollector);
|
||||
this.mediaSource = mediaSource;
|
||||
if (this.mediaSource != null) {
|
||||
this.mediaSource.removeEventListener(analyticsCollector);
|
||||
analyticsCollector.resetForNewMediaSource();
|
||||
}
|
||||
this.mediaSource = mediaSource;
|
||||
mediaSource.addEventListener(eventHandler, analyticsCollector);
|
||||
@AudioFocusManager.PlayerCommand
|
||||
int playerCommand = audioFocusManager.handlePrepare(getPlayWhenReady());
|
||||
updatePlayWhenReady(getPlayWhenReady(), playerCommand);
|
||||
@ -949,8 +955,10 @@ public class SimpleExoPlayer
|
||||
player.stop(reset);
|
||||
if (mediaSource != null) {
|
||||
mediaSource.removeEventListener(analyticsCollector);
|
||||
mediaSource = null;
|
||||
analyticsCollector.resetForNewMediaSource();
|
||||
if (reset) {
|
||||
mediaSource = null;
|
||||
}
|
||||
}
|
||||
audioFocusManager.handleStop();
|
||||
currentCues = Collections.emptyList();
|
||||
@ -969,6 +977,7 @@ public class SimpleExoPlayer
|
||||
}
|
||||
if (mediaSource != null) {
|
||||
mediaSource.removeEventListener(analyticsCollector);
|
||||
mediaSource = null;
|
||||
}
|
||||
bandwidthMeter.removeEventListener(analyticsCollector);
|
||||
currentCues = Collections.emptyList();
|
||||
|
@ -79,6 +79,11 @@ public abstract class StubExoPlayer implements ExoPlayer {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retry() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(MediaSource mediaSource) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
Loading…
x
Reference in New Issue
Block a user