# IdlingMediaCodecAdapterFactory

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

*** ** * ** ***


```
@UnstableApi
public final class IdlingMediaCodecAdapterFactory implements MediaCodecAdapter.Factory
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.Factory` which can `https://robolectric.org/javadoc/4.11/org/robolectric/shadows/ShadowLooper.html#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 |
|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/IdlingMediaCodecAdapterFactory#IdlingMediaCodecAdapterFactory(android.content.Context)(https://developer.android.com/reference/android/content/Context.html context)` Constructs an instance with no automatic idling. |
| `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/IdlingMediaCodecAdapterFactory#IdlingMediaCodecAdapterFactory(android.content.Context,androidx.media3.common.util.Clock)(https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/androidx/media3/common/util/Clock clock)` Constructs an instance which automatically idles the async threads using `clock`. |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter` | `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/IdlingMediaCodecAdapterFactory#createAdapter(androidx.media3.exoplayer.mediacodec.MediaCodecAdapter.Configuration)(https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.Configuration configuration)` Creates a `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter` instance. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/IdlingMediaCodecAdapterFactory#idleQueueingAndCallbackThreads()()` Calls `https://robolectric.org/javadoc/4.11/org/robolectric/shadows/ShadowLooper.html#idle--` on all created queueing and callback threads with a non-null `https://developer.android.com/reference/android/os/HandlerThread.html#getLooper()`. |

| ### Inherited Constants |
|---|
| From [androidx.media3.exoplayer.mediacodec.MediaCodecAdapter.Factory](https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.Factory) |---|---| | `static final https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.Factory` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.Factory#DEFAULT()` **This field is deprecated.** Use `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.Factory#getDefault(android.content.Context)` instead. <br /> | |

| ### Inherited methods |
|---|
| From [androidx.media3.exoplayer.mediacodec.MediaCodecAdapter.Factory](https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.Factory) |---|---| | `static https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.Factory` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.Factory#getDefault(android.content.Context)(https://developer.android.com/reference/android/content/Context.html context)` 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 `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/IdlingMediaCodecAdapterFactory#idleQueueingAndCallbackThreads()`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | A `https://developer.android.com/reference/android/content/Context.html`. |

### 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 `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/IdlingMediaCodecAdapterFactory#idleQueueingAndCallbackThreads()`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | A `https://developer.android.com/reference/android/content/Context.html`. |
| `https://developer.android.com/reference/androidx/media3/common/util/Clock clock` | A clock to schedule the idling operations with. |

## Public methods

### createAdapter

```
public MediaCodecAdapter createAdapter(MediaCodecAdapter.Configuration configuration)
```

Creates a `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter` instance.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### idleQueueingAndCallbackThreads

```
public void idleQueueingAndCallbackThreads()
```

Calls `https://robolectric.org/javadoc/4.11/org/robolectric/shadows/ShadowLooper.html#idle--` on all created queueing and callback threads with a non-null `https://developer.android.com/reference/android/os/HandlerThread.html#getLooper()`.