Use TransformationException for error listener parameter.
PiperOrigin-RevId: 416307600
This commit is contained in:
parent
039b9154e9
commit
cdc0e2e618
@ -24,6 +24,7 @@ import android.net.Uri;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.media3.common.MediaItem;
|
import androidx.media3.common.MediaItem;
|
||||||
|
import androidx.media3.transformer.TransformationException;
|
||||||
import androidx.media3.transformer.Transformer;
|
import androidx.media3.transformer.Transformer;
|
||||||
import androidx.test.platform.app.InstrumentationRegistry;
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -79,7 +80,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTransformationError(MediaItem inputMediaItem, Exception exception) {
|
public void onTransformationError(
|
||||||
|
MediaItem inputMediaItem, TransformationException exception) {
|
||||||
exceptionReference.set(exception);
|
exceptionReference.set(exception);
|
||||||
countDownLatch.countDown();
|
countDownLatch.countDown();
|
||||||
}
|
}
|
||||||
|
@ -468,19 +468,26 @@ public final class Transformer {
|
|||||||
public interface Listener {
|
public interface Listener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the transformation is completed.
|
* Called when the transformation is completed successfully.
|
||||||
*
|
*
|
||||||
* @param inputMediaItem The {@link MediaItem} for which the transformation is completed.
|
* @param inputMediaItem The {@link MediaItem} for which the transformation is completed.
|
||||||
*/
|
*/
|
||||||
default void onTransformationCompleted(MediaItem inputMediaItem) {}
|
default void onTransformationCompleted(MediaItem inputMediaItem) {}
|
||||||
|
|
||||||
|
/** @deprecated Use {@link #onTransformationError(MediaItem, TransformationException)}. */
|
||||||
|
@Deprecated
|
||||||
|
default void onTransformationError(MediaItem inputMediaItem, Exception exception) {
|
||||||
|
onTransformationError(inputMediaItem, (TransformationException) exception);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called if an error occurs during the transformation.
|
* Called if an exception occurs during the transformation.
|
||||||
*
|
*
|
||||||
* @param inputMediaItem The {@link MediaItem} for which the error occurs.
|
* @param inputMediaItem The {@link MediaItem} for which the exception occurs.
|
||||||
* @param exception The exception describing the error.
|
* @param exception The {@link TransformationException} describing the exception.
|
||||||
*/
|
*/
|
||||||
default void onTransformationError(MediaItem inputMediaItem, Exception exception) {}
|
default void onTransformationError(
|
||||||
|
MediaItem inputMediaItem, TransformationException exception) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Provider for views to show diagnostic information during transformation, for debugging. */
|
/** Provider for views to show diagnostic information during transformation, for debugging. */
|
||||||
|
@ -238,9 +238,8 @@ public final class TransformerTest {
|
|||||||
MediaItem mediaItem = MediaItem.fromUri("asset:///non-existing-path.mp4");
|
MediaItem mediaItem = MediaItem.fromUri("asset:///non-existing-path.mp4");
|
||||||
|
|
||||||
transformer.startTransformation(mediaItem, outputPath);
|
transformer.startTransformation(mediaItem, outputPath);
|
||||||
Exception exception = TransformerTestRunner.runUntilError(transformer);
|
TransformationException exception = TransformerTestRunner.runUntilError(transformer);
|
||||||
|
|
||||||
assertThat(exception).isInstanceOf(TransformationException.class);
|
|
||||||
assertThat(exception).hasCauseThat().isInstanceOf(ExoPlaybackException.class);
|
assertThat(exception).hasCauseThat().isInstanceOf(ExoPlaybackException.class);
|
||||||
assertThat(exception).hasCauseThat().hasCauseThat().isInstanceOf(IOException.class);
|
assertThat(exception).hasCauseThat().hasCauseThat().isInstanceOf(IOException.class);
|
||||||
}
|
}
|
||||||
@ -252,9 +251,8 @@ public final class TransformerTest {
|
|||||||
MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_WITH_ALL_SAMPLE_FORMATS_UNSUPPORTED);
|
MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_WITH_ALL_SAMPLE_FORMATS_UNSUPPORTED);
|
||||||
|
|
||||||
transformer.startTransformation(mediaItem, outputPath);
|
transformer.startTransformation(mediaItem, outputPath);
|
||||||
Exception exception = TransformerTestRunner.runUntilError(transformer);
|
TransformationException exception = TransformerTestRunner.runUntilError(transformer);
|
||||||
|
|
||||||
assertThat(exception).isInstanceOf(TransformationException.class);
|
|
||||||
assertThat(exception).hasCauseThat().isInstanceOf(IllegalStateException.class);
|
assertThat(exception).hasCauseThat().isInstanceOf(IllegalStateException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,8 +56,9 @@ public final class TransformerTestRunner {
|
|||||||
* @throws IllegalStateException If the method is not called from the main thread, or if the
|
* @throws IllegalStateException If the method is not called from the main thread, or if the
|
||||||
* transformation completes without error.
|
* transformation completes without error.
|
||||||
*/
|
*/
|
||||||
public static Exception runUntilError(Transformer transformer) throws TimeoutException {
|
public static TransformationException runUntilError(Transformer transformer)
|
||||||
@Nullable Exception exception = runUntilListenerCalled(transformer);
|
throws TimeoutException {
|
||||||
|
@Nullable TransformationException exception = runUntilListenerCalled(transformer);
|
||||||
if (exception == null) {
|
if (exception == null) {
|
||||||
throw new IllegalStateException("The transformation completed without error.");
|
throw new IllegalStateException("The transformation completed without error.");
|
||||||
}
|
}
|
||||||
@ -65,7 +66,8 @@ public final class TransformerTestRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static Exception runUntilListenerCalled(Transformer transformer) throws TimeoutException {
|
private static TransformationException runUntilListenerCalled(Transformer transformer)
|
||||||
|
throws TimeoutException {
|
||||||
TransformationResult transformationResult = new TransformationResult();
|
TransformationResult transformationResult = new TransformationResult();
|
||||||
Transformer.Listener listener =
|
Transformer.Listener listener =
|
||||||
new Transformer.Listener() {
|
new Transformer.Listener() {
|
||||||
@ -75,7 +77,8 @@ public final class TransformerTestRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTransformationError(MediaItem inputMediaItem, Exception exception) {
|
public void onTransformationError(
|
||||||
|
MediaItem inputMediaItem, TransformationException exception) {
|
||||||
transformationResult.exception = exception;
|
transformationResult.exception = exception;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -88,6 +91,6 @@ public final class TransformerTestRunner {
|
|||||||
|
|
||||||
private static class TransformationResult {
|
private static class TransformationResult {
|
||||||
public boolean isCompleted;
|
public boolean isCompleted;
|
||||||
@Nullable public Exception exception;
|
@Nullable public TransformationException exception;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user