# CacheBitmapLoader

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

*** ** * ** ***

<br />

```
@UnstableApi
class CacheBitmapLoader : BitmapLoader
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/media3/common/util/BitmapLoader` that caches the result of the last `https://developer.android.com/reference/kotlin/androidx/media3/session/CacheBitmapLoader#decodeBitmap(byte[])`, `https://developer.android.com/reference/kotlin/androidx/media3/session/CacheBitmapLoader#loadBitmap(android.net.Uri)` or `https://developer.android.com/reference/kotlin/androidx/media3/session/CacheBitmapLoader#loadBitmapFromMetadata(androidx.media3.common.MediaMetadata)` request.

Requests are fulfilled from the last bitmap load request when the last bitmap is requested from the same `data`, the same `uri`, or the same `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaMetadata#artworkUri()` or `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaMetadata#artworkData()`. If the request doesn't match the previous request, the request is forwarded to the provided `https://developer.android.com/reference/kotlin/androidx/media3/common/util/BitmapLoader` and the result is cached.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/session/CacheBitmapLoader#CacheBitmapLoader(androidx.media3.common.util.BitmapLoader)(bitmapLoader: https://developer.android.com/reference/kotlin/androidx/media3/common/util/BitmapLoader!)` Creates an instance that is able to cache the last bitmap load request to the given bitmap loader. |

| ### Public functions |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/android/graphics/Bitmap.html!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/session/CacheBitmapLoader#decodeBitmap(byte[])(data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!)` Decodes an image from compressed binary data. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/android/graphics/Bitmap.html!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/session/CacheBitmapLoader#loadBitmap(android.net.Uri)(uri: https://developer.android.com/reference/android/net/Uri.html!)` Loads an image from `uri`. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/android/graphics/Bitmap.html!>?` | `https://developer.android.com/reference/kotlin/androidx/media3/session/CacheBitmapLoader#loadBitmapFromMetadata(androidx.media3.common.MediaMetadata)(metadata: https://developer.android.com/reference/kotlin/androidx/media3/common/MediaMetadata!)` Loads an image from `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaMetadata`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/session/CacheBitmapLoader#supportsMimeType(java.lang.String)(mimeType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Returns whether the given `mimeType` is supported. |

## Public constructors

### CacheBitmapLoader

```
CacheBitmapLoader(bitmapLoader: BitmapLoader!)
```

Creates an instance that is able to cache the last bitmap load request to the given bitmap loader.

## Public functions

### decodeBitmap

```
fun decodeBitmap(data: ByteArray<Byte>!): ListenableFuture<Bitmap!>!
```

Decodes an image from compressed binary data.

### loadBitmap

```
fun loadBitmap(uri: Uri!): ListenableFuture<Bitmap!>!
```

Loads an image from `uri`.

### loadBitmapFromMetadata

```
fun loadBitmapFromMetadata(metadata: MediaMetadata!): ListenableFuture<Bitmap!>?
```

Loads an image from `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaMetadata`. Returns null if `metadata` doesn't contain bitmap information.

By default, the method will try to decode an image from `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaMetadata#artworkData()` if it is present. Otherwise, the method will try to load an image from `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaMetadata#artworkUri()` if it is present. The method will return null if neither `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaMetadata#artworkData()` nor `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaMetadata#artworkUri()` is present.

### supportsMimeType

```
fun supportsMimeType(mimeType: String!): Boolean
```

Returns whether the given `mimeType` is supported.