Commit 09230a67 by kimvde Committed by Ian Baker

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
parent 8e7ab9c8
...@@ -114,11 +114,13 @@ public final class TransformerActivity extends AppCompatActivity { ...@@ -114,11 +114,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();
......
...@@ -516,6 +516,7 @@ public final class Transformer { ...@@ -516,6 +516,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,
...@@ -734,11 +735,13 @@ public final class Transformer { ...@@ -734,11 +735,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;
} }
/** /**
...@@ -896,10 +899,19 @@ public final class Transformer { ...@@ -896,10 +899,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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment