Switch audio tracks

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:

1playerViewController.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.

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

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

Get available audio tracks

1let audioTracks = playerViewController.getAudioTracks()

Get the current audio track

1let currentTrack = playerViewController.getCurrentAudioTrack()

Switch audio tracks

1// Switch by track ID
2playerViewController.setAudioTrack(trackId: track.id)

Handle audio track events

Conform to FastPixAudioTrackDelegate to receive track updates:

1extension VideoPlayerViewController: FastPixAudioTrackDelegate {
2
3 // Called when audio tracks are loaded or updated
4 func onAudioTracksUpdated(tracks: [AudioTrack]) {
5 print("Available audio tracks:", tracks)
6 }
7
8 // Called when the active audio track changes
9 func onAudioTrackChange(selectedTrack: AudioTrack) {
10 print("Audio switched to:", selectedTrack.label)
11 }
12
13 // Called when a track switch fails
14 func onAudioTrackFailed(error: AudioTrackError) {
15 print("Audio switch failed:", error)
16 }
17
18 // Called when a track switch starts or finishes
19 func onAudioTrackSwitching(isSwitching: Bool) {
20 if isSwitching {
21 // Show loading indicator
22 } else {
23 // Hide loading indicator
24 }
25 }
26}

AudioTrack model

PropertyTypeDescription
idStringUnique identifier for the track
languageCodeStringBCP-47 language tag (for example, "hi", "en")
languageNameStringDisplay name of the language (for example, "Hindi")
labelStringHuman-readable label shown in UI
isSelectedBoolWhether this track is currently active
isDefaultBoolWhether this is the default track