@UnstableApi
public final class RawAssetLoader implements AssetLoader


An AssetLoader implementation that loads raw audio and/or video data.

Typically instantiated in a custom AssetLoader.Factory saving a reference to the created RawAssetLoader.

Provide raw audio data as input by calling queueAudioData. This method must always be called from the same thread, which can be any thread.

Provide video frames as input by calling queueInputTexture, then signal the end of input when finished. These two methods must be called from the same thread, which can be any thread.

All other methods are for internal use only and must never be called.

Summary

Public constructors

RawAssetLoader(
    EditedMediaItem editedMediaItem,
    AssetLoader.Listener assetLoaderListener,
    @Nullable Format audioFormat,
    @Nullable Format videoFormat,
    @Nullable OnInputFrameProcessedListener frameProcessedListener
)

Creates an instance.

Public methods

ImmutableMap<IntegerString>

Return the used decoders' names.

int

Returns the current Transformer.ProgressState and updates progressHolder with the current progress if it is available.

boolean
queueAudioData(
    ByteBuffer audioData,
    long presentationTimeUs,
    boolean isLast
)

Attempts to provide raw audio data.

boolean
queueInputTexture(int texId, long presentationTimeUs)

Attempts to provide an input texture.

void

Stops loading data and releases all resources associated with the asset loader.

void

Signals that no further input frames will be rendered.

void

Starts the asset loader.

Inherited Constants

From androidx.media3.transformer.AssetLoader
static final int

Indicates that the asset loader can output decoded samples.

static final int

Indicates that the asset loader can output encoded samples.

Public constructors

RawAssetLoader

public RawAssetLoader(
    EditedMediaItem editedMediaItem,
    AssetLoader.Listener assetLoaderListener,
    @Nullable Format audioFormat,
    @Nullable Format videoFormat,
    @Nullable OnInputFrameProcessedListener frameProcessedListener
)

Creates an instance.

Parameters
EditedMediaItem editedMediaItem

The EditedMediaItem for which raw data is provided. The durationUs must be set.

AssetLoader.Listener assetLoaderListener

Listener for asset loading events.

@Nullable Format audioFormat

The audio format, or null if only video data is provided.

@Nullable Format videoFormat

The video format, or null if only audio data is provided. The width and the height must be set.

@Nullable OnInputFrameProcessedListener frameProcessedListener

Listener for the event when a frame has been processed, or null if only audio data is provided. The listener receives a GL sync object (if supported) to allow reusing the texture after it's no longer in use.

Public methods

getDecoderNames

public ImmutableMap<IntegerStringgetDecoderNames()

Return the used decoders' names.

Returns
ImmutableMap<IntegerString>

The decoders' names keyed by track type.

getProgress

@Transformer.ProgressState
public int getProgress(ProgressHolder progressHolder)

Returns the current Transformer.ProgressState and updates progressHolder with the current progress if it is available.

Parameters
ProgressHolder progressHolder

A ProgressHolder, updated to hold the percentage progress if available.

Returns
int

The Transformer.ProgressState.

queueAudioData

public boolean queueAudioData(
    ByteBuffer audioData,
    long presentationTimeUs,
    boolean isLast
)

Attempts to provide raw audio data.

Parameters
ByteBuffer audioData

The raw audio data. The ByteBuffer can be reused after calling this method.

long presentationTimeUs

The presentation time for the raw audio data, in microseconds.

boolean isLast

Signals the last audio data.

Returns
boolean

Whether the raw audio data was successfully queued. If false, the caller should try again later.

queueInputTexture

public boolean queueInputTexture(int texId, long presentationTimeUs)

Attempts to provide an input texture.

Must be called on the same thread as signalEndOfVideoInput.

Parameters
int texId

The ID of the texture to queue.

long presentationTimeUs

The presentation time for the texture, in microseconds.

Returns
boolean

Whether the texture was successfully queued. If false, the caller should try again later.

release

public void release()

Stops loading data and releases all resources associated with the asset loader.

signalEndOfVideoInput

public void signalEndOfVideoInput()

Signals that no further input frames will be rendered.

Must be called on the same thread as queueInputTexture.

start

public void start()

Starts the asset loader.