> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://fastpix.com/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://fastpix.com/docs/_mcp/server.

# Switch audio tracks

> Learn how to discover and switch between audio tracks in the FastPix Android Player.

Learn how to discover and switch between audio tracks in the FastPix Android Player.

`FastPixPlayer` can discover and switch audio tracks, commonly available on HLS streams with multiple audio renditions.

## AudioTrack properties

Each `AudioTrack` includes the following properties (useful for building a UI):

* `id`: pass this to `setAudioTrack(id)` to switch tracks.
* `languageCode` / `languageName` / `label`: display in your language menu.
* `isSelected`, `isPlayable`, `isDefault`: for UI state.
* Optional diagnostics: `role`, `channels`, `codec`, `bitrate`, `groupId`.

## Listen for audio track updates

```kotlin
import io.fastpix.media3.tracks.AudioTrackListener
import io.fastpix.media3.tracks.AudioTrackUpdateReason

player.addAudioTrackListener(object : AudioTrackListener {
    override fun onAudioTracksLoaded(tracks: List<AudioTrack>, reason: AudioTrackUpdateReason) {
        // reason is INITIAL, MEDIA_CHANGED, or TRACKS_UPDATED
        // Populate your UI (language menu, etc.)
    }
    override fun onAudioTracksChange(selectedTrack: AudioTrack) {
        // Update selected state in your UI
    }
    override fun onAudioTrackSwitching(isSwitching: Boolean) {
        // Optional: show/hide a "switching" indicator
    }
    override fun onAudioTracksLoadedFailed(error: AudioTrackError) {
        // Handle invalid id, player not ready, selection failure, etc.
    }
})
```

## Switch audio track by ID

> **Note:** If a seek is in progress, the SDK defers switching until the seek completes.

```kotlin
val tracks = player.getAudioTracks()
val current = player.getCurrentAudioTrack()   // currently selected track, null if only one track or none
val target = tracks.firstOrNull() ?: return
player.setAudioTrack(target.id)
```

## Set a default audio language

Set a preferred audio language that applies automatically when tracks become available. This never overrides a manual selection:

```kotlin
player.setDefaultAudioTrack(languageName = "English")
```

Use BCP-47 / ISO language names like `"English"`, `"Hindi"`, `"French"`. If the preferred language doesn't exist in the stream, the player keeps its normal selection.

## Build a language menu

```kotlin
val tracks = player.getAudioTracks()
val items = tracks.filter { it.isPlayable }.map { t ->
    val title = t.languageName ?: t.label ?: t.languageCode ?: "Unknown"
    title to t.id
}
// Present items in a dialog; on click: player.setAudioTrack(id)
```

## Remove the audio track listener

Keep a reference to your `AudioTrackListener` and remove it when it is no longer needed:

```kotlin
player.removeAudioTrackListener(listener)
```

\


#### Frequently asked questions

Call `player.setAudioTrack(id)` with an id from `getAudioTracks()` to switch immediately, or call `player.setDefaultAudioTrack(languageName = "Hindi")` so a preferred language is applied automatically when tracks load. Switching does not restart playback: position and state are preserved.

Audio track switching works on media that provides multiple audio renditions, which HLS streams commonly do. Read the tracks with `player.getAudioTracks()`, then call `player.setAudioTrack(track.id)`. If a seek is in progress, the SDK defers the switch until the seek completes.

Call `player.setDefaultAudioTrack(languageName = "English")` with a BCP-47 / ISO language name. The preference is applied automatically when tracks become available, such as after loading new media, and it never overrides a manual selection. If the language is not in the stream, the player keeps its normal selection.

Each `AudioTrack` exposes `id` (pass it to `setAudioTrack`), plus `languageCode`, `languageName`, and `label` for your menu, and `isSelected`, `isPlayable`, and `isDefault` for UI state. Optional diagnostics include `role`, `channels`, `codec`, `bitrate`, and `groupId`.

\


## What's next

* [Switch subtitle tracks](/docs/android-player/switch-subtitle-tracks) to let viewers turn captions on, off, or into another language.
* [Switch video quality](/docs/android-player/switch-video-quality) so users can lock a fixed resolution or return to adaptive auto mode.
* [Listen to playback events](/docs/android-player/listen-to-playback-events) to keep your track menus and player UI in sync.