# DefaultMuxer

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

*** ** * ** ***


```
@UnstableApi
public final class DefaultMuxer implements Muxer
```

<br />

*** ** * ** ***

A default `https://developer.android.com/reference/androidx/media3/muxer/Muxer` implementation.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/transformer/DefaultMuxer.Factory implements https://developer.android.com/reference/androidx/media3/muxer/Muxer.Factory` A `https://developer.android.com/reference/androidx/media3/muxer/Muxer.Factory` for `https://developer.android.com/reference/androidx/media3/transformer/DefaultMuxer`. |

| ### Constants |
|---|---|
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/transformer/DefaultMuxer#MUXER_NAME()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/transformer/DefaultMuxer#addMetadataEntry(androidx.media3.common.Metadata.Entry)(https://developer.android.com/reference/androidx/media3/common/Metadata.Entry metadataEntry)` Adds `https://developer.android.com/reference/androidx/media3/common/Metadata.Entry` about the output file. |
| `int` | `https://developer.android.com/reference/androidx/media3/transformer/DefaultMuxer#addTrack(androidx.media3.common.Format)(https://developer.android.com/reference/androidx/media3/common/Format format)` Adds a track of the given media format. |
| `void` | `https://developer.android.com/reference/androidx/media3/transformer/DefaultMuxer#close()()` Closes the file. |
| `void` | `https://developer.android.com/reference/androidx/media3/transformer/DefaultMuxer#writeSampleData(int,java.nio.ByteBuffer,androidx.media3.muxer.BufferInfo)( int trackId, https://developer.android.com/reference/java/nio/ByteBuffer.html byteBuffer, https://developer.android.com/reference/androidx/media3/muxer/BufferInfo bufferInfo )` Writes encoded sample data. |

| ### Inherited methods |
|---|
| From [java.lang.AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable.html) |---|---| | `abstract void` | `https://developer.android.com/reference/java/lang/AutoCloseable.html#close()()` | |

## Constants

### MUXER_NAME

```
public static final String MUXER_NAME
```

## Public methods

### addMetadataEntry

```
public void addMetadataEntry(Metadata.Entry metadataEntry)
```

Adds `https://developer.android.com/reference/androidx/media3/common/Metadata.Entry` about the output file.

### addTrack

```
public int addTrack(Format format)
```

Adds a track of the given media format.

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

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Format format` | The `https://developer.android.com/reference/androidx/media3/common/Format` of the track. |

| Returns |
|---|---|
| `int` | A track id for this track, which should be passed to `https://developer.android.com/reference/androidx/media3/muxer/Muxer#writeSampleData(int,java.nio.ByteBuffer,androidx.media3.muxer.BufferInfo)`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/muxer/MuxerException` | If the muxer encounters a problem while adding the track. |

### close

```
public void close()
```

Closes the file.

The muxer cannot be used anymore once this method returns.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/muxer/MuxerException` | If the muxer fails to finish writing the output. |

### writeSampleData

```
public void writeSampleData(
    int trackId,
    ByteBuffer byteBuffer,
    BufferInfo bufferInfo
)
```

Writes encoded sample data.

| Parameters |
|---|---|
| `int trackId` | The track id, previously returned by `https://developer.android.com/reference/androidx/media3/muxer/Muxer#addTrack(androidx.media3.common.Format)`. |
| `https://developer.android.com/reference/java/nio/ByteBuffer.html byteBuffer` | A buffer containing the sample data to write to the container. |
| `https://developer.android.com/reference/androidx/media3/muxer/BufferInfo bufferInfo` | The `https://developer.android.com/reference/androidx/media3/muxer/BufferInfo` of the sample. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/muxer/MuxerException` | If the muxer fails to write the sample. |