> 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 detect and switch between multiple audio tracks in the FastPix iOS Player.

Learn how to detect and switch between multiple audio tracks in the FastPix iOS Player.

The FastPix iOS Player SDK automatically detects all available audio tracks from the stream and lets users switch between them during playback. This is useful for multi-language content.

## Set up the audio track delegate

Assign the delegate to receive audio track updates:

```swift
playerViewController.audioTrackDelegate = self
```

## Set a preferred audio track

Set a preferred audio track by language name. The SDK automatically selects it when the video loads. If the preferred track isn't available, the manifest default is used.

```swift
// Pass the display name of the language (case-insensitive)
playerViewController.setPreferredAudioTrack("Hindi")
```

The preferred track is automatically applied on every playlist item change.

## Get available audio tracks

```swift
let audioTracks = playerViewController.getAudioTracks()
```

## Get the current audio track

```swift
let currentTrack = playerViewController.getCurrentAudioTrack()
```

## Switch audio tracks

```swift
// Switch by track ID
playerViewController.setAudioTrack(trackId: track.id)
```

## Handle audio track events

Conform to `FastPixAudioTrackDelegate` to receive track updates:

```swift
extension VideoPlayerViewController: FastPixAudioTrackDelegate {

    // Called when audio tracks are loaded or updated
    func onAudioTracksUpdated(tracks: [AudioTrack]) {
        print("Available audio tracks:", tracks)
    }

    // Called when the active audio track changes
    func onAudioTrackChange(selectedTrack: AudioTrack) {
        print("Audio switched to:", selectedTrack.label)
    }

    // Called when a track switch fails
    func onAudioTrackFailed(error: AudioTrackError) {
        print("Audio switch failed:", error)
    }

    // Called when a track switch starts or finishes
    func onAudioTrackSwitching(isSwitching: Bool) {
        if isSwitching {
            // Show loading indicator
        } else {
            // Hide loading indicator
        }
    }
}
```

## AudioTrack model

| Property       | Type     | Description                                           |
| -------------- | -------- | ----------------------------------------------------- |
| `id`           | `String` | Unique identifier for the track                       |
| `languageCode` | `String` | BCP-47 language tag (for example, `"hi"`, `"en"`)     |
| `languageName` | `String` | Display name of the language (for example, `"Hindi"`) |
| `label`        | `String` | Human-readable label shown in UI                      |
| `isSelected`   | `Bool`   | Whether this track is currently active                |
| `isDefault`    | `Bool`   | Whether this is the default track                     |