From babc9c69c604caea4481edff4488cfbe3a1cbf40 Mon Sep 17 00:00:00 2001 From: sheenachhabra Date: Mon, 24 Jun 2024 10:55:38 -0700 Subject: [PATCH] Remove unnecessary FileChannel from Mp4Muxer As per the documentation, closing a `FileOutputStream` automatically closes the associated `FileChannel`. PiperOrigin-RevId: 646152280 --- .../main/java/androidx/media3/muxer/Mp4Muxer.java | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) 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 a3fe966ce7..cedcf15108 100644 --- a/libraries/muxer/src/main/java/androidx/media3/muxer/Mp4Muxer.java +++ b/libraries/muxer/src/main/java/androidx/media3/muxer/Mp4Muxer.java @@ -39,7 +39,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; /** * A muxer for creating an MP4 container file. @@ -181,7 +180,6 @@ public final class Mp4Muxer implements Muxer { private static final String TAG = "Mp4Muxer"; private final FileOutputStream fileOutputStream; - private final FileChannel fileChannel; private final MetadataCollector metadataCollector; private final Mp4Writer mp4Writer; @@ -192,13 +190,12 @@ public final class Mp4Muxer implements Muxer { boolean sampleCopyEnabled, boolean attemptStreamableOutputEnabled) { this.fileOutputStream = fileOutputStream; - this.fileChannel = fileOutputStream.getChannel(); metadataCollector = new MetadataCollector(); Mp4MoovStructure moovStructure = new Mp4MoovStructure(metadataCollector, lastFrameDurationBehavior); mp4Writer = new Mp4Writer( - fileChannel, + fileOutputStream.getChannel(), moovStructure, annexBToAvccConverter, sampleCopyEnabled, @@ -302,15 +299,6 @@ public final class Mp4Muxer implements Muxer { } catch (IOException e) { exception = new MuxerException("Failed to finish writing samples", e); } - try { - fileChannel.close(); - } catch (IOException e) { - if (exception == null) { - exception = new MuxerException("Failed to close output channel", e); - } else { - Log.e(TAG, "Failed to close output channel", e); - } - } try { fileOutputStream.close(); } catch (IOException e) {