# TrackGroup

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/common/TrackGroup "View this page in Java")

<br />

```
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[Tracks.Group](https://developer.android.com/reference/kotlin/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 constructors                                                                                                                                                                                                                                                                                                |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `@`[UnstableApi](https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi) [TrackGroup](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup#TrackGroup(androidx.media3.common.Format...))`(formats: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!>!)` Constructs a track group containing the provided`formats`.                                                                                                             |
| `@`[UnstableApi](https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi) [TrackGroup](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup#TrackGroup(java.lang.String,androidx.media3.common.Format...))`(id: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!, formats: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!>!)` Constructs a track group with the provided`id`and`formats`. |

|                                              ### Public functions                                               |
|-----------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [TrackGroup](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup)`!`               | `@`[UnstableApi](https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi) [copyWithId](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup#copyWithId(java.lang.String))`(id: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!)` Returns a copy of this track group with the specified`id`.                                        |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                             | [equals](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup#equals(java.lang.Object))`(obj: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?)`                                                                                                                                                                                                                         |
| `java-static `[TrackGroup](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup)`!` | `@`[UnstableApi](https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi) [fromBundle](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup#fromBundle(android.os.Bundle))`(bundle: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`!)` Restores a`TrackGroup`from a[Bundle](https://developer.android.com/reference/android/os/Bundle.html). |
| [Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!`                       | `@`[UnstableApi](https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi) [getFormat](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup#getFormat(int))`(index: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns the format of the track at a given index.                                                                    |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                     | [hashCode](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup#hashCode())`()`                                                                                                                                                                                                                                                                                                                        |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                     | `@`[UnstableApi](https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi) [indexOf](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup#indexOf(androidx.media3.common.Format))`(format: `[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!)` Returns the index of the track with the given format in the group.                |
| [Bundle](https://developer.android.com/reference/android/os/Bundle.html)`!`                                     | `@`[UnstableApi](https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi) [toBundle](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup#toBundle())`()`                                                                                                                                                                                                               |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`                            | [toString](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup#toString())`()`                                                                                                                                                                                                                                                                                                                        |

|                                ### Public properties                                 |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | `@`[UnstableApi](https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi) [id](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup#id()) An identifier for the track group.                                                                                                       |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | `@`[UnstableApi](https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi) [length](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup#length()) The number of tracks in the group.                                                                                               |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | `@`[UnstableApi](https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi) `@`[C.TrackType](https://developer.android.com/reference/kotlin/androidx/media3/common/C.TrackType) [type](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup#type()) The type of tracks in the group. |

## Public constructors

### TrackGroup

```
@UnstableApi
TrackGroup(formats: Array<Format!>!)
```

Constructs a track group containing the provided`formats`.  

|                                                                                        Parameters                                                                                        |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
| `formats: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!>!` | The list of[Formats](https://developer.android.com/reference/kotlin/androidx/media3/common/Format). Must not be empty. |

### TrackGroup

```
@UnstableApi
TrackGroup(id: String!, formats: Array<Format!>!)
```

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

|                                                                                        Parameters                                                                                        |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
| `id: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`                                                                                               | The identifier of the track group. May be an empty string.                                                             |
| `formats: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!>!` | The list of[Formats](https://developer.android.com/reference/kotlin/androidx/media3/common/Format). Must not be empty. |

## Public functions

### copyWithId

```
@UnstableApi
fun copyWithId(id: String!): TrackGroup!
```

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

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|-------------------------------------------------|
| `id: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | The identifier for the copy of the track group. |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-------------------------|
| [TrackGroup](https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup)`!` | The copied track group. |

### equals

```
fun equals(obj: Any?): Boolean
```  

### fromBundle

```
@UnstableApi
java-static fun fromBundle(bundle: Bundle!): TrackGroup!
```

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

### getFormat

```
@UnstableApi
fun getFormat(index: Int): Format!
```

Returns the format of the track at a given index.  

|                                      Parameters                                      |
|--------------------------------------------------------------------------------------|-------------------------|
| `index: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The index of the track. |

|                                          Returns                                          |
|-------------------------------------------------------------------------------------------|---------------------|
| [Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!` | The track's format. |

### hashCode

```
fun hashCode(): Int
```  

### indexOf

```
@UnstableApi
fun indexOf(format: Format!): Int
```

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                                              |
|-----------------------------------------------------------------------------------------------------|-------------|
| `format: `[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!` | The format. |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The index of the track, or[INDEX_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#INDEX_UNSET())if no such track exists. |

### toBundle

```
@UnstableApi
fun toBundle(): Bundle!
```  

### toString

```
fun toString(): String!
```  

## Public properties

### id

```
@UnstableApi
val id: String!
```

An identifier for the track group.  

### length

```
@UnstableApi
val length: Int
```

The number of tracks in the group.  

### type

```
@UnstableApi
@C.TrackType
val type: Int
```

The type of tracks in the group.