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 4598cc9248)
This commit is contained in:
sheenachhabra 2022-11-09 17:00:14 +00:00 committed by microkatz
parent 1ffe6a73da
commit 70f74fde15
2 changed files with 9 additions and 12 deletions

View file

@ -49,8 +49,6 @@ import com.google.android.exoplayer2.util.Util;
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;
@ -669,17 +667,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);
@ -703,6 +695,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.
*/
@ -714,6 +707,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 {