# MetadataRetriever

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

*** ** * ** ***

<br />

```
@UnstableApi
public final class MetadataRetriever implements AutoCloseable
```

<br />

*** ** * ** ***

Retrieves information from a `https://developer.android.com/reference/androidx/media3/common/MediaItem` without playback.

This class is intended for extracting metadata from media formats supported by Media3 players (such as `https://developer.android.com/reference/androidx/media3/exoplayer/ExoPlayer`) for playback. It is not designed as a general-purpose metadata extractor for non-playback formats, such as standalone images. To extract properties like height, width, and rotation from images, use `https://developer.android.com/reference/androidx/exifinterface/media/ExifInterface`.

An instance is created for a single `https://developer.android.com/reference/androidx/media3/common/MediaItem` via a `https://developer.android.com/reference/androidx/media3/inspector/MetadataRetriever.Builder`. It provides methods to asynchronously retrieve metadata. The instance must be `https://developer.android.com/reference/androidx/media3/inspector/MetadataRetriever#close()` after use to release resources.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/inspector/MetadataRetriever.Builder` Builder for `https://developer.android.com/reference/androidx/media3/inspector/MetadataRetriever` instances. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/inspector/MetadataRetriever#DEFAULT_MAXIMUM_PARALLEL_RETRIEVALS() = 5` The default number of maximum parallel retrievals. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/inspector/MetadataRetriever#close()()` |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Long.html>` | `https://developer.android.com/reference/androidx/media3/inspector/MetadataRetriever#retrieveDurationUs()()` Asynchronously retrieves the duration for the `https://developer.android.com/reference/androidx/media3/common/MediaItem`. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/androidx/media3/common/Timeline>` | `https://developer.android.com/reference/androidx/media3/inspector/MetadataRetriever#retrieveTimeline()()` Asynchronously retrieves the `https://developer.android.com/reference/androidx/media3/common/Timeline` for the `https://developer.android.com/reference/androidx/media3/common/MediaItem`. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/androidx/media3/exoplayer/source/TrackGroupArray>` | `https://developer.android.com/reference/androidx/media3/inspector/MetadataRetriever#retrieveTrackGroups()()` Asynchronously retrieves the `https://developer.android.com/reference/androidx/media3/exoplayer/source/TrackGroupArray` for the `https://developer.android.com/reference/androidx/media3/common/MediaItem`. |
| `static void` | `https://developer.android.com/reference/androidx/media3/inspector/MetadataRetriever#setMaximumParallelRetrievals(int)(int maximumParallelRetrievals)` Sets the maximum number of metadata retrievals run in parallel. |

## Constants

### DEFAULT_MAXIMUM_PARALLEL_RETRIEVALS

```
public static final int DEFAULT_MAXIMUM_PARALLEL_RETRIEVALS = 5
```

The default number of maximum parallel retrievals.

## Public methods

### close

```
public void close()
```

### retrieveDurationUs

```
public ListenableFuture<Long> retrieveDurationUs()
```

Asynchronously retrieves the duration for the `https://developer.android.com/reference/androidx/media3/common/MediaItem`.

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Long.html>` | A `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` that will be populated with the duration in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if unknown. |

### retrieveTimeline

```
public ListenableFuture<Timeline> retrieveTimeline()
```

Asynchronously retrieves the `https://developer.android.com/reference/androidx/media3/common/Timeline` for the `https://developer.android.com/reference/androidx/media3/common/MediaItem`.

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/androidx/media3/common/Timeline>` | A `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` that will be populated with the `https://developer.android.com/reference/androidx/media3/common/Timeline`. |

### retrieveTrackGroups

```
public ListenableFuture<TrackGroupArray> retrieveTrackGroups()
```

Asynchronously retrieves the `https://developer.android.com/reference/androidx/media3/exoplayer/source/TrackGroupArray` for the `https://developer.android.com/reference/androidx/media3/common/MediaItem`.

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/androidx/media3/exoplayer/source/TrackGroupArray>` | A `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` that will be populated with the `https://developer.android.com/reference/androidx/media3/exoplayer/source/TrackGroupArray`. |

### setMaximumParallelRetrievals

```
public static void setMaximumParallelRetrievals(int maximumParallelRetrievals)
```

Sets the maximum number of metadata retrievals run in parallel.

The default is `https://developer.android.com/reference/androidx/media3/inspector/MetadataRetriever#DEFAULT_MAXIMUM_PARALLEL_RETRIEVALS()`.

| Parameters |
|---|---|
| `int maximumParallelRetrievals` | The maximum number of parallel retrievals. |