# PreCacheHelper

# PreCacheHelper

Artifact:[androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3)  
[View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/source/preload/PreCacheHelper.java+class:androidx.media3.exoplayer.source.preload.PreCacheHelper)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/PreCacheHelper "View this page in Java")

<br />

```
@UnstableApi
class PreCacheHelper
```

<br />

*** ** * ** ***

A helper for pre-caching a single media.

## Summary

|                                                                                                                                           ### Nested types                                                                                                                                           |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `class `[PreCacheHelper.Factory](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/preload/PreCacheHelper.Factory) A factory for[PreCacheHelper](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/preload/PreCacheHelper).              |
| `interface `[PreCacheHelper.Listener](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/preload/PreCacheHelper.Listener) A listener for[PreCacheHelper](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/preload/PreCacheHelper)events. |

|                             ### Public functions                              |
|-------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [preCache](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/preload/PreCacheHelper#preCache(long,long))`(startPositionMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`, durationMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Pre-caches the underlying media from a`startPositionMs`and for a`durationMs`. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [release](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/preload/PreCacheHelper#release(boolean))`(removeCachedContent: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Releases the[PreCacheHelper](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/preload/PreCacheHelper).                                |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [stop](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/preload/PreCacheHelper#stop())`()` Stops the pre-caching.                                                                                                                                                                                                                                                                      |

## Public functions

### preCache

```
fun preCache(startPositionMs: Long, durationMs: Long): Unit
```

Pre-caches the underlying media from a`startPositionMs`and for a`durationMs`.

Can be called from any thread.  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
| `startPositionMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The start position from which the media should be pre-cached, in milliseconds. |
| `durationMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)      | The duration for which the media should be pre-cached, in milliseconds.        |

### release

```
fun release(removeCachedContent: Boolean): Unit
```

Releases the[PreCacheHelper](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/preload/PreCacheHelper).

Can be called from any thread.  

|                                                 Parameters                                                 |
|------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `removeCachedContent: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether the cached content should be removed. If`true`, the[PreCacheHelper](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/preload/PreCacheHelper)will create a new thread to remove the cached content. |

### stop

```
fun stop(): Unit
```

Stops the pre-caching.

Can be called from any thread.