Change UnsupportedEncodingException to IllegalArgumentException

In startTransformation method we were throwing UnsupportedEncodingException (IOException) when mediaItem with unsupported arguments is passed.
Changed this to IllegalArgumentException which seems more logical here.

PiperOrigin-RevId: 487259296
(cherry picked from commit 818bf4a20a)
This commit is contained in:
sheenachhabra 2022-11-09 17:00:14 +00:00 committed by microkatz
parent 707c2d894d
commit bc3aef081e
2 changed files with 9 additions and 12 deletions

View file

@ -50,8 +50,6 @@ import androidx.media3.extractor.mp4.Mp4Extractor;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@ -671,17 +669,11 @@ public final class Transformer {
* @param mediaItem The {@link MediaItem} to transform.
* @param path The path to the output file.
* @throws IllegalArgumentException If the path is invalid.
* @throws IllegalArgumentException If the {@link MediaItem} is not supported.
* @throws IllegalStateException If this method is called from the wrong thread.
* @throws IllegalStateException If a transformation is already in progress.
* @throws IOException If {@link MediaItem} is not supported.
*/
public void startTransformation(MediaItem mediaItem, String path) throws IOException {
if (!mediaItem.clippingConfiguration.equals(MediaItem.ClippingConfiguration.UNSET)
&& transformationRequest.flattenForSlowMotion) {
// TODO(b/233986762): Support clipping with SEF flattening.
throw new UnsupportedEncodingException(
"Clipping is not supported when slow motion flattening is requested");
}
public void startTransformation(MediaItem mediaItem, String path) {
this.outputPath = path;
this.outputParcelFileDescriptor = null;
startTransformationInternal(mediaItem);
@ -705,6 +697,7 @@ public final class Transformer {
* transformation is completed. It is the responsibility of the caller to close the
* ParcelFileDescriptor. This can be done after this method returns.
* @throws IllegalArgumentException If the file descriptor is invalid.
* @throws IllegalArgumentException If the {@link MediaItem} is not supported.
* @throws IllegalStateException If this method is called from the wrong thread.
* @throws IllegalStateException If a transformation is already in progress.
*/
@ -716,6 +709,12 @@ public final class Transformer {
}
private void startTransformationInternal(MediaItem mediaItem) {
if (!mediaItem.clippingConfiguration.equals(MediaItem.ClippingConfiguration.UNSET)
&& transformationRequest.flattenForSlowMotion) {
// TODO(b/233986762): Support clipping with SEF flattening.
throw new IllegalArgumentException(
"Clipping is not supported when slow motion flattening is requested");
}
verifyApplicationThread();
if (transformationInProgress) {
throw new IllegalStateException("There is already a transformation in progress.");

View file

@ -581,8 +581,6 @@ public final class TransformerEndToEndTest {
() -> {
try {
transformer.startTransformation(mediaItem, outputPath);
} catch (IOException e) {
// Do nothing.
} catch (IllegalStateException e) {
illegalStateException.set(e);
} finally {