# TrackGroup

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

*** ** * ** ***


```
public final class TrackGroup
```

<br />

*** ** * ** ***

An immutable group of tracks available within a media stream. All tracks in a group present the same content, but their formats may differ.

As an example of how tracks can be grouped, consider an adaptive playback where a main video feed is provided in five resolutions, and an alternative video feed (e.g., a different camera angle in a sports match) is provided in two resolutions. In this case there will be two video track groups, one corresponding to the main video feed containing five tracks, and a second for the alternative video feed containing two tracks.

Note that audio tracks whose languages differ are not grouped, because content in different languages is not considered to be the same. Conversely, audio tracks in the same language that only differ in properties such as bitrate, sampling rate, channel count and so on can be grouped. This also applies to text tracks.

Note also that this class only contains information derived from the media itself. Unlike `https://developer.android.com/reference/androidx/media3/common/Tracks.Group`, it does not include runtime information such as the extent to which playback of each track is supported by the device, or which tracks are currently selected.

## Summary

| ### Public fields |
|---|---|
| `final https://developer.android.com/reference/java/lang/String.html` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/TrackGroup#id()` An identifier for the track group. |
| `final int` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/TrackGroup#length()` The number of tracks in the group. |
| `final int` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi @https://developer.android.com/reference/androidx/media3/common/C.TrackType https://developer.android.com/reference/androidx/media3/common/TrackGroup#type()` The type of tracks in the group. |

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/TrackGroup#TrackGroup(androidx.media3.common.Format...)(Format[] formats)` Constructs a track group containing the provided `formats`. |
| `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/TrackGroup#TrackGroup(java.lang.String,androidx.media3.common.Format...)(https://developer.android.com/reference/java/lang/String.html id, Format[] formats)` Constructs a track group with the provided `id` and `formats`. |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/TrackGroup` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/TrackGroup#copyWithId(java.lang.String)(https://developer.android.com/reference/java/lang/String.html id)` Returns a copy of this track group with the specified `id`. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/common/TrackGroup#equals(java.lang.Object)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html obj)` |
| `static https://developer.android.com/reference/androidx/media3/common/TrackGroup` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/TrackGroup#fromBundle(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html bundle)` Restores a `TrackGroup` from a `https://developer.android.com/reference/android/os/Bundle.html`. |
| `https://developer.android.com/reference/androidx/media3/common/Format` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/TrackGroup#getFormat(int)(int index)` Returns the format of the track at a given index. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/TrackGroup#hashCode()()` |
| `int` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/TrackGroup#indexOf(androidx.media3.common.Format)(https://developer.android.com/reference/androidx/media3/common/Format format)` Returns the index of the track with the given format in the group. |
| `https://developer.android.com/reference/android/os/Bundle.html` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/TrackGroup#toBundle()()` |
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/common/TrackGroup#toString()()` |

## Public fields

### id

```
@UnstableApi
public final String id
```

An identifier for the track group.

### length

```
@UnstableApi
public final int length
```

The number of tracks in the group.

### type

```
@UnstableApi
@C.TrackType
public final int type
```

The type of tracks in the group.

## Public constructors

### TrackGroup

```
@UnstableApi
public TrackGroup(Format[] formats)
```

Constructs a track group containing the provided `formats`.

| Parameters |
|---|---|
| `Format[] formats` | The list of `https://developer.android.com/reference/androidx/media3/common/Format`. Must not be empty. |

### TrackGroup

```
@UnstableApi
public TrackGroup(String id, Format[] formats)
```

Constructs a track group with the provided `id` and `formats`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html id` | The identifier of the track group. May be an empty string. |
| `Format[] formats` | The list of `https://developer.android.com/reference/androidx/media3/common/Format`. Must not be empty. |

## Public methods

### copyWithId

```
@UnstableApi
public TrackGroup copyWithId(String id)
```

Returns a copy of this track group with the specified `id`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html id` | The identifier for the copy of the track group. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/TrackGroup` | The copied track group. |

### equals

```
public boolean equals(@Nullable Object obj)
```

### fromBundle

```
@UnstableApi
public static TrackGroup fromBundle(Bundle bundle)
```

Restores a `TrackGroup` from a `https://developer.android.com/reference/android/os/Bundle.html`.

### getFormat

```
@UnstableApi
public Format getFormat(int index)
```

Returns the format of the track at a given index.

| Parameters |
|---|---|
| `int index` | The index of the track. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Format` | The track's format. |

### hashCode

```
public int hashCode()
```

### indexOf

```
@UnstableApi
public int indexOf(Format format)
```

Returns the index of the track with the given format in the group. The format is located by identity so, for example, `group.indexOf(group.getFormat(index)) == index` even if multiple tracks have formats that contain the same values.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Format format` | The format. |

| Returns |
|---|---|
| `int` | The index of the track, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if no such track exists. |

### toBundle

```
@UnstableApi
public Bundle toBundle()
```

### toString

```
public String toString()
```