# IdlingMediaCodecAdapterFactory

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/test/utils/robolectric/IdlingMediaCodecAdapterFactory "View this page in Java")

<br />

```
@UnstableApi
class IdlingMediaCodecAdapterFactory : MediaCodecAdapter.Factory
```

<br />

*** ** * ** ***

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

|                                                     ### Public functions                                                      |
|-------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [MediaCodecAdapter](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter)`!` | [createAdapter](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/robolectric/IdlingMediaCodecAdapterFactory#createAdapter(androidx.media3.exoplayer.mediacodec.MediaCodecAdapter.Configuration))`(configuration: `[MediaCodecAdapter.Configuration](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.Configuration)`!)` Creates a[MediaCodecAdapter](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter)instance. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                 | [idleQueueingAndCallbackThreads](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/robolectric/IdlingMediaCodecAdapterFactory#idleQueueingAndCallbackThreads())`()` Calls[idle](https://robolectric.org/javadoc/4.11/org/robolectric/shadows/ShadowLooper.html#idle--)on all created queueing and callback threads with a non-null[looper](https://developer.android.com/reference/android/os/HandlerThread.html#getLooper()).                                                                                             |

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

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ### Inherited functions                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From[androidx.media3.exoplayer.mediacodec.MediaCodecAdapter.Factory](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.Factory) |-------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `java-static `[MediaCodecAdapter.Factory](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.Factory)`!` | [getDefault](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.Factory#getDefault(android.content.Context))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!)` Returns the default factory that should be used in most cases. | |

## Public constructors

### IdlingMediaCodecAdapterFactory

```
IdlingMediaCodecAdapterFactory(context: Context!)
```

Constructs an instance with no automatic idling. The async threads can be manually idled with[idleQueueingAndCallbackThreads](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/robolectric/IdlingMediaCodecAdapterFactory#idleQueueingAndCallbackThreads()).  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!` | A[Context](https://developer.android.com/reference/android/content/Context.html). |

### IdlingMediaCodecAdapterFactory

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

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

## Public functions

### createAdapter

```
fun createAdapter(configuration: MediaCodecAdapter.Configuration!): MediaCodecAdapter!
```

Creates a[MediaCodecAdapter](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter)instance.  

|                                         Throws                                          |
|-----------------------------------------------------------------------------------------|---|
| [java.io.IOException](https://developer.android.com/reference/java/io/IOException.html) |   |

### idleQueueingAndCallbackThreads

```
fun idleQueueingAndCallbackThreads(): Unit
```

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