> Documentation index: https://developer.android.com/reference/llms.txt

# Muxer

Artifact: [androidx.media3:media3-muxer](https://developer.android.com/jetpack/androidx/releases/media3.md.txt) [View Source](https://cs.android.com/search?q=file:androidx/media3/muxer/Muxer.java+class:androidx.media3.muxer.Muxer)

*** ** * ** ***


```
@UnstableApi
interface Muxer : AutoCloseable
```

<br />

Known direct subclasses [AacMuxer](https://developer.android.com/reference/kotlin/androidx/media3/muxer/AacMuxer.md.txt), [DefaultMuxer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultMuxer.md.txt), [FragmentedMp4Muxer](https://developer.android.com/reference/kotlin/androidx/media3/muxer/FragmentedMp4Muxer.md.txt), [FrameworkMuxer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/FrameworkMuxer.md.txt), [InAppFragmentedMp4Muxer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/InAppFragmentedMp4Muxer.md.txt), [InAppMp4Muxer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/InAppMp4Muxer.md.txt), [Mp4Muxer](https://developer.android.com/reference/kotlin/androidx/media3/muxer/Mp4Muxer.md.txt), [OggMuxer](https://developer.android.com/reference/kotlin/androidx/media3/muxer/OggMuxer.md.txt), [WavMuxer](https://developer.android.com/reference/kotlin/androidx/media3/muxer/WavMuxer.md.txt), [WebmMuxer](https://developer.android.com/reference/kotlin/androidx/media3/muxer/WebmMuxer.md.txt)

|---|---|
| `AacMuxer` | A muxer for creating an AAC (Advanced Audio Coding) container file. |
| `DefaultMuxer` | A default `Muxer` implementation. |
| `FragmentedMp4Muxer` | A muxer for creating a fragmented MP4 file. |
| `FrameworkMuxer` | `Muxer` implementation that uses a `MediaMuxer`. |
| `InAppFragmentedMp4Muxer` | `Muxer` implementation that uses a `FragmentedMp4Muxer`. |
| `InAppMp4Muxer` | `Muxer` implementation that uses an `Mp4Muxer`. |
| `Mp4Muxer` | A muxer for creating an MP4 container file. |
| `OggMuxer` | A muxer for creating an Ogg container file. |
| `WavMuxer` | A muxer for creating a WAV container file. |
| `WebmMuxer` | A muxer for creating a WebM container file. |

*** ** * ** ***

A muxer for producing media container files.

## Summary

| ### Nested types |
|---|
| `interface Muxer.Factory` Factory for muxers. |

| ### Public functions |
|---|---|
| `Unit` | `addMetadataEntry(metadataEntry: Metadata.Entry!)` Adds `metadata` about the output file. |
| `Int` | `addTrack(format: Format!)` Adds a track of the given media format. |
| `Unit` | `close()` Closes the file. |
| `Unit` | `writeSampleData( trackId: Int, byteBuffer: ByteBuffer!, bufferInfo: BufferInfo! )` Writes encoded sample data. |

## Public functions

### addMetadataEntry

```
fun addMetadataEntry(metadataEntry: Metadata.Entry!): Unit
```

Adds `metadata` about the output file.

| Parameters |
|---|---|
| `metadataEntry: Metadata.Entry!` | The `Metadata.Entry` to add. |

| Throws |
|---|---|
| `java.lang.IllegalStateException` | If the muxer is closed. |

### addTrack

```
fun addTrack(format: Format!): Int
```

Adds a track of the given media format.

All tracks must be added before any samples are written to any track.

| Parameters |
|---|---|
| `format: Format!` | The `Format` of the track. |

| Returns |
|---|---|
| `Int` | A track id for this track, which should be passed to `writeSampleData`. |

| Throws |
|---|---|
| `androidx.media3.muxer.MuxerException` | If the muxer encounters a problem while adding the track. |
| `java.lang.IllegalStateException` | If the muxer is closed. |

### close

```
fun close(): Unit
```

Closes the file.

The muxer cannot be used anymore once this method is called, even if it throws. Implementations must make further calls to this method a no-op and, once it has been called, must throw an `IllegalStateException` from all other methods.

| Throws |
|---|---|
| `androidx.media3.muxer.MuxerException` | If the muxer fails to finish writing the output. |

### writeSampleData

```
fun writeSampleData(
    trackId: Int,
    byteBuffer: ByteBuffer!,
    bufferInfo: BufferInfo!
): Unit
```

Writes encoded sample data.

| Parameters |
|---|---|
| `trackId: Int` | The track id, previously returned by `addTrack`. |
| `byteBuffer: ByteBuffer!` | A buffer containing the sample data to write to the container. |
| `bufferInfo: BufferInfo!` | The `BufferInfo` of the sample. |

| Throws |
|---|---|
| `androidx.media3.muxer.MuxerException` | If the muxer fails to write the sample. |
| `java.lang.IllegalStateException` | If the muxer is closed. |