# 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
public final class CacheBitmapLoader implements BitmapLoader
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/common/util/BitmapLoader` that caches the result of the last `https://developer.android.com/reference/androidx/media3/session/CacheBitmapLoader#decodeBitmap(byte[])`, `https://developer.android.com/reference/androidx/media3/session/CacheBitmapLoader#loadBitmap(android.net.Uri)` or `https://developer.android.com/reference/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/androidx/media3/common/MediaMetadata#artworkUri()` or `https://developer.android.com/reference/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/androidx/media3/common/util/BitmapLoader` and the result is cached.

## Summary

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

| ### Public methods |
|---|---|
| `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/androidx/media3/session/CacheBitmapLoader#decodeBitmap(byte[])(byte[] data)` 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/androidx/media3/session/CacheBitmapLoader#loadBitmap(android.net.Uri)(https://developer.android.com/reference/android/net/Uri.html uri)` Loads an image from `uri`. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable 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/androidx/media3/session/CacheBitmapLoader#loadBitmapFromMetadata(androidx.media3.common.MediaMetadata)(https://developer.android.com/reference/androidx/media3/common/MediaMetadata metadata)` Loads an image from `https://developer.android.com/reference/androidx/media3/common/MediaMetadata`. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/session/CacheBitmapLoader#supportsMimeType(java.lang.String)(https://developer.android.com/reference/java/lang/String.html mimeType)` Returns whether the given `mimeType` is supported. |

## Public constructors

### CacheBitmapLoader

```
public CacheBitmapLoader(BitmapLoader bitmapLoader)
```

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

## Public methods

### decodeBitmap

```
public ListenableFuture<Bitmap> decodeBitmap(byte[] data)
```

Decodes an image from compressed binary data.

### loadBitmap

```
public ListenableFuture<Bitmap> loadBitmap(Uri uri)
```

Loads an image from `uri`.

### loadBitmapFromMetadata

```
public @Nullable ListenableFuture<Bitmap> loadBitmapFromMetadata(MediaMetadata metadata)
```

Loads an image from `https://developer.android.com/reference/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/androidx/media3/common/MediaMetadata#artworkData()` if it is present. Otherwise, the method will try to load an image from `https://developer.android.com/reference/androidx/media3/common/MediaMetadata#artworkUri()` if it is present. The method will return null if neither `https://developer.android.com/reference/androidx/media3/common/MediaMetadata#artworkData()` nor `https://developer.android.com/reference/androidx/media3/common/MediaMetadata#artworkUri()` is present.

### supportsMimeType

```
public boolean supportsMimeType(String mimeType)
```

Returns whether the given `mimeType` is supported.