IdlingMediaCodecAdapterFactory


@UnstableApi
public final class IdlingMediaCodecAdapterFactory implements MediaCodecAdapter.Factory


A MediaCodecAdapter.Factory which can idle all the async queueing and callback threads used in async MediaCodec mode.

This helps ensure that buffers are reliably queued and dequeued from MediaCodec as the playback thread advances in tests. Without this, the queueing and callback threads run freely and often make little progress before the test completes, leading to flakiness and unpredictable results.

Summary

Public constructors

Constructs an instance with no automatic idling.

Constructs an instance which automatically idles the async threads using clock.

Public methods

MediaCodecAdapter

Creates a MediaCodecAdapter instance.

void

Calls idle on all created queueing and callback threads with a non-null looper.

Inherited Constants

From androidx.media3.exoplayer.mediacodec.MediaCodecAdapter.Factory
static final MediaCodecAdapter.Factory

This field is deprecated.

Use getDefault instead.

Inherited methods

From androidx.media3.exoplayer.mediacodec.MediaCodecAdapter.Factory
static MediaCodecAdapter.Factory

Returns the default factory that should be used in most cases.

Public constructors

IdlingMediaCodecAdapterFactory

public IdlingMediaCodecAdapterFactory(Context context)

Constructs an instance with no automatic idling. The async threads can be manually idled with idleQueueingAndCallbackThreads.

Parameters
Context context

A Context.

IdlingMediaCodecAdapterFactory

public IdlingMediaCodecAdapterFactory(Context context, Clock clock)

Constructs an instance which automatically idles the async threads using clock.

The async threads can also be manually idled with idleQueueingAndCallbackThreads.

Parameters
Context context

A Context.

Clock clock

A clock to schedule the idling operations with.

Public methods

createAdapter

public MediaCodecAdapter createAdapter(MediaCodecAdapter.Configuration configuration)

Creates a MediaCodecAdapter instance.

idleQueueingAndCallbackThreads

public void idleQueueingAndCallbackThreads()

Calls idle on all created queueing and callback threads with a non-null looper.