diff --git a/libraries/muxer/src/main/java/androidx/media3/muxer/Mp4Muxer.java b/libraries/muxer/src/main/java/androidx/media3/muxer/Mp4Muxer.java index f6b10dba74..45e1607c91 100644 --- a/libraries/muxer/src/main/java/androidx/media3/muxer/Mp4Muxer.java +++ b/libraries/muxer/src/main/java/androidx/media3/muxer/Mp4Muxer.java @@ -105,18 +105,32 @@ import org.checkerframework.checker.nullness.qual.EnsuresNonNull; */ @UnstableApi public final class Mp4Muxer implements Muxer { - /** Provides temporary cache files to be used by the muxer. */ - public interface CacheFileProvider { + /** Parameters for {@link #FILE_FORMAT_EDITABLE_VIDEO}. */ + public static final class EditableVideoParameters { + /** Provides temporary cache files to be used by the muxer. */ + public interface CacheFileProvider { + + /** + * Returns a cache file path. + * + *
Every call to this method should return a new cache file. + * + *
The app is responsible for deleting the cache file after {@linkplain Mp4Muxer#close() + * closing} the muxer. + */ + String getCacheFilePath(); + } + + public final CacheFileProvider cacheFileProvider; /** - * Returns a cache file path. + * Creates an instance. * - *
Every call to this method should return a new cache file. - * - *
The app is responsible for deleting the cache file after {@linkplain Mp4Muxer#close() - * closing} the muxer. + * @param cacheFileProvider A {@link CacheFileProvider}. */ - String getCacheFilePath(); + public EditableVideoParameters(CacheFileProvider cacheFileProvider) { + this.cacheFileProvider = cacheFileProvider; + } } /** Behavior for the last sample duration. */ @@ -167,7 +181,7 @@ public final class Mp4Muxer implements Muxer { private boolean sampleCopyEnabled; private boolean attemptStreamableOutputEnabled; private @FileFormat int outputFileFormat; - @Nullable private CacheFileProvider cacheFileProvider; + @Nullable private EditableVideoParameters editableVideoParameters; /** * Creates a {@link Builder} instance with default values. @@ -243,8 +257,8 @@ public final class Mp4Muxer implements Muxer { * *
The default value is {@link #FILE_FORMAT_DEFAULT}. * - *
For {@link #FILE_FORMAT_EDITABLE_VIDEO}, a {@link CacheFileProvider} must also be - * {@linkplain #setCacheFileProvider(CacheFileProvider) set}. + *
For {@link #FILE_FORMAT_EDITABLE_VIDEO}, {@link EditableVideoParameters} must also be + * {@linkplain #setEditableVideoParameters(EditableVideoParameters)} set}. */ @CanIgnoreReturnValue public Mp4Muxer.Builder setOutputFileFormat(@FileFormat int fileFormat) { @@ -252,18 +266,21 @@ public final class Mp4Muxer implements Muxer { return this; } - /** Sets the {@link CacheFileProvider}. */ + /** Sets the {@link EditableVideoParameters}. */ @CanIgnoreReturnValue - public Mp4Muxer.Builder setCacheFileProvider(CacheFileProvider cacheFileProvider) { - this.cacheFileProvider = cacheFileProvider; + public Mp4Muxer.Builder setEditableVideoParameters( + EditableVideoParameters editableVideoParameters) { + this.editableVideoParameters = editableVideoParameters; return this; } /** Builds an {@link Mp4Muxer} instance. */ public Mp4Muxer build() { checkArgument( - outputFileFormat != FILE_FORMAT_EDITABLE_VIDEO || cacheFileProvider != null, - "A CacheFileProvider must be set for FILE_FORMAT_EDITABLE_VIDEO"); + outputFileFormat == FILE_FORMAT_EDITABLE_VIDEO + ? editableVideoParameters != null + : editableVideoParameters == null, + "EditablevideoParameters must be set for FILE_FORMAT_EDITABLE_VIDEO"); return new Mp4Muxer( outputStream, lastFrameDurationBehavior, @@ -271,7 +288,7 @@ public final class Mp4Muxer implements Muxer { sampleCopyEnabled, attemptStreamableOutputEnabled, outputFileFormat, - cacheFileProvider); + editableVideoParameters); } } @@ -284,7 +301,7 @@ public final class Mp4Muxer implements Muxer { private final boolean sampleCopyEnabled; private final boolean attemptStreamableOutputEnabled; private final @FileFormat int outputFileFormat; - @Nullable private final CacheFileProvider cacheFileProvider; + @Nullable private final EditableVideoParameters editableVideoParameters; private final MetadataCollector metadataCollector; private final Mp4Writer mp4Writer; private final List