@UnstableApi
public final class InAppMuxer implements Muxer


Muxer implementation that uses a Mp4Muxer.

Summary

Nested types

public final class InAppMuxer.Factory implements Muxer.Factory

Muxer.Factory for InAppMuxer.

public final class InAppMuxer.Factory.Builder

A builder for Factory instances.

Provides metadata to add in the output MP4 file.

Public fields

final long

Public methods

void

Adds Metadata about the output file.

int
addTrack(Format format)

Adds a track with the specified format.

long

Returns the maximum delay allowed between output samples, in milliseconds, or TIME_UNSET if there is no maximum.

void
release(boolean forCancellation)

Finishes writing the output and releases any resources associated with muxing.

void
writeSampleData(
    int trackIndex,
    ByteBuffer data,
    long presentationTimeUs,
    @C.BufferFlags int flags
)

Writes the specified sample.

Public fields

maxDelayBetweenSamplesMs

public final long maxDelayBetweenSamplesMs

Public methods

addMetadata

public void addMetadata(Metadata metadata)

Adds Metadata about the output file.

addTrack

public int addTrack(Format format)

Adds a track with the specified format.

Parameters
Format format

The Format of the track.

Returns
int

The index for this track, which should be passed to writeSampleData.

Throws
androidx.media3.transformer.Muxer.MuxerException

If the muxer encounters a problem while adding the track.

getMaxDelayBetweenSamplesMs

public long getMaxDelayBetweenSamplesMs()

Returns the maximum delay allowed between output samples, in milliseconds, or TIME_UNSET if there is no maximum.

This is the maximum delay between samples of any track. They can be of the same or of different track types.

This value is used to abort the export when the maximum delay is reached. Note that there is no guarantee that the export will be aborted exactly at that time.

release

public void release(boolean forCancellation)

Finishes writing the output and releases any resources associated with muxing.

The muxer cannot be used anymore once this method has been called.

Parameters
boolean forCancellation

Whether the reason for releasing the resources is the export cancellation.

Throws
androidx.media3.transformer.Muxer.MuxerException

If the muxer fails to finish writing the output and forCancellation is false.

writeSampleData

public void writeSampleData(
    int trackIndex,
    ByteBuffer data,
    long presentationTimeUs,
    @C.BufferFlags int flags
)

Writes the specified sample.

Parameters
int trackIndex

The index of the track, previously returned by addTrack.

ByteBuffer data

A buffer containing the sample data to write to the container.

long presentationTimeUs

The presentation time of the sample in microseconds.

@C.BufferFlags int flags

The C.BufferFlags associated with the data. Only BUFFER_FLAG_KEY_FRAME and BUFFER_FLAG_END_OF_STREAM are supported.

Throws
androidx.media3.transformer.Muxer.MuxerException

If the muxer fails to write the sample.