SurfaceAssetLoader


@UnstableApi
public final class SurfaceAssetLoader implements AssetLoader


Asset loader that outputs video data passed to its input Surface.

To use this asset loader, pass a callback to the factory's constructor to get access to the underlying asset loader and Surface to write to once they are ready. Then pass the factory to setAssetLoaderFactory.

The media item passed to transformer must have a URI starting with the scheme MEDIA_ITEM_URI_SCHEME.

Call signalEndOfInput when the input stream ends, which will cause the transformation to complete.

Summary

Nested types

Callbacks for SurfaceAssetLoader events.

public final class SurfaceAssetLoader.Factory implements AssetLoader.Factory

Factory for SurfaceAssetLoader instances.

Constants

static final String
MEDIA_ITEM_URI_SCHEME = "transformer_surface_asset"

URI scheme for creating a MediaItem that signals that the media is provided from this asset loader.

Public fields

final EditedMediaItem

Public methods

ImmutableMap<IntegerString>

Return the used decoders' names.

EditedMediaItem

Returns the EditedMediaItem being loaded by this instance.

int

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

void

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

void
setContentFormat(Format contentFormat)

Sets the video content format, which must have a raw video sample MIME type, width, height and color info.

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.

Constants

MEDIA_ITEM_URI_SCHEME

public static final String MEDIA_ITEM_URI_SCHEME = "transformer_surface_asset"

URI scheme for creating a MediaItem that signals that the media is provided from this asset loader.

Public fields

editedMediaItem

public final EditedMediaItem editedMediaItem

Public methods

getDecoderNames

public ImmutableMap<IntegerStringgetDecoderNames()

Return the used decoders' names.

Returns
ImmutableMap<IntegerString>

The decoders' names keyed by track type.

getEditedMediaItem

public EditedMediaItem getEditedMediaItem()

Returns the EditedMediaItem being loaded by this instance.

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.

release

public void release()

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

setContentFormat

public void setContentFormat(Format contentFormat)

Sets the video content format, which must have a raw video sample MIME type, width, height and color info. May be called on any thread.

signalEndOfInput

public void signalEndOfInput()

Signals that no further input frames will be rendered. May be called on any thread.

start

public void start()

Starts the asset loader.