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:
kimvde 2022-02-15 16:56:49 +00:00 committed by Ian Baker
parent b9b1be4f3e
commit 5ed7523158
2 changed files with 18 additions and 4 deletions

View File

@ -113,11 +113,13 @@ public final class TransformerActivity extends AppCompatActivity {
protected void onStop() {
super.onStop();
checkNotNull(transformationStopwatch).reset();
checkNotNull(transformer).cancel();
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();
releasePlayer();

View File

@ -508,6 +508,7 @@ public final class Transformer {
@Nullable private MuxerWrapper muxerWrapper;
@Nullable private ExoPlayer player;
private @ProgressState int progressState;
private boolean isCancelling;
private Transformer(
Context context,
@ -725,11 +726,13 @@ public final class Transformer {
* @throws IllegalStateException If this method is called from the wrong thread.
*/
public void cancel() {
isCancelling = true;
try {
releaseResources(/* forCancellation= */ true);
} catch (TransformationException impossible) {
throw new IllegalStateException(impossible);
}
isCancelling = false;
}
/**
@ -887,10 +890,19 @@ public final class Transformer {
@Override
public void onPlayerError(PlaybackException error) {
@Nullable Throwable cause = error.getCause();
handleTransformationEnded(
TransformationException transformationException =
cause instanceof TransformationException
? (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) {