mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Handle player release timing out in transformer
- The resources were released twice before, which is not necessary since the MSG_RELEASE message is already in the internal player queue. - The demo app was failing because the stop watch was stopped in onTransformationError after being reset. #minor-release #mse-bug-week PiperOrigin-RevId: 428794426
This commit is contained in:
parent
b9b1be4f3e
commit
5ed7523158
@ -113,11 +113,13 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
|
||||||
checkNotNull(transformationStopwatch).reset();
|
|
||||||
|
|
||||||
checkNotNull(transformer).cancel();
|
checkNotNull(transformer).cancel();
|
||||||
transformer = null;
|
transformer = null;
|
||||||
|
|
||||||
|
// The stop watch is reset after cancelling the transformation, in case cancelling causes the
|
||||||
|
// stop watch to be stopped in a transformer callback.
|
||||||
|
checkNotNull(transformationStopwatch).reset();
|
||||||
|
|
||||||
checkNotNull(playerView).onPause();
|
checkNotNull(playerView).onPause();
|
||||||
releasePlayer();
|
releasePlayer();
|
||||||
|
|
||||||
|
@ -508,6 +508,7 @@ public final class Transformer {
|
|||||||
@Nullable private MuxerWrapper muxerWrapper;
|
@Nullable private MuxerWrapper muxerWrapper;
|
||||||
@Nullable private ExoPlayer player;
|
@Nullable private ExoPlayer player;
|
||||||
private @ProgressState int progressState;
|
private @ProgressState int progressState;
|
||||||
|
private boolean isCancelling;
|
||||||
|
|
||||||
private Transformer(
|
private Transformer(
|
||||||
Context context,
|
Context context,
|
||||||
@ -725,11 +726,13 @@ public final class Transformer {
|
|||||||
* @throws IllegalStateException If this method is called from the wrong thread.
|
* @throws IllegalStateException If this method is called from the wrong thread.
|
||||||
*/
|
*/
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
|
isCancelling = true;
|
||||||
try {
|
try {
|
||||||
releaseResources(/* forCancellation= */ true);
|
releaseResources(/* forCancellation= */ true);
|
||||||
} catch (TransformationException impossible) {
|
} catch (TransformationException impossible) {
|
||||||
throw new IllegalStateException(impossible);
|
throw new IllegalStateException(impossible);
|
||||||
}
|
}
|
||||||
|
isCancelling = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -887,10 +890,19 @@ public final class Transformer {
|
|||||||
@Override
|
@Override
|
||||||
public void onPlayerError(PlaybackException error) {
|
public void onPlayerError(PlaybackException error) {
|
||||||
@Nullable Throwable cause = error.getCause();
|
@Nullable Throwable cause = error.getCause();
|
||||||
handleTransformationEnded(
|
TransformationException transformationException =
|
||||||
cause instanceof TransformationException
|
cause instanceof TransformationException
|
||||||
? (TransformationException) cause
|
? (TransformationException) cause
|
||||||
: TransformationException.createForPlaybackException(error));
|
: TransformationException.createForPlaybackException(error);
|
||||||
|
if (isCancelling) {
|
||||||
|
// Resources are already being released.
|
||||||
|
listeners.queueEvent(
|
||||||
|
/* eventFlag= */ C.INDEX_UNSET,
|
||||||
|
listener -> listener.onTransformationError(mediaItem, transformationException));
|
||||||
|
listeners.flushEvents();
|
||||||
|
} else {
|
||||||
|
handleTransformationEnded(transformationException);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleTransformationEnded(@Nullable TransformationException exception) {
|
private void handleTransformationEnded(@Nullable TransformationException exception) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user