For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
StatusSupportDiscussionsLog inSign Up
Docs HomeAPI ReferenceVideo on DemandAI FeaturesLive StreamingVideo PlayerVideo DataCloud PlayoutRecipes
Docs HomeAPI ReferenceVideo on DemandAI FeaturesLive StreamingVideo PlayerVideo DataCloud PlayoutRecipes
  • Player SDKs
    • Introduction
  • Web player
    • Install the FastPix web player
    • Play uploaded videos
    • Handle playback errors
  • Android player
    • Install FastPix Android player
    • Set up the player
    • Play uploaded videos
    • Handle playback errors
      • Enable secure video playback
      • Use custom domain
      • Switch audio tracks
      • Switch subtitle tracks
      • Add seek preview thumbnails
      • Enable fullscreen mode
      • Monitor video data
  • iOS player
    • Install FastPix iOS player
    • Play uploaded videos
    • Handle playback errors
  • Flutter player
    • Install FastPix Flutter player
    • Play uploaded videos
    • Handle playback errors
LogoLogo
StatusSupportDiscussionsLog inSign Up
On this page
  • AudioTrack properties
  • Listen for audio track updates
  • Switch audio track by ID
  • Set a default audio language
  • Build a language menu
Android playerAdvanced features

Switch audio tracks

Was this page helpful?
Previous

Switch subtitle tracks

Next
Built with

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

1import io.fastpix.media3.tracks.AudioTrackListener
2import io.fastpix.media3.tracks.AudioTrackUpdateReason
3
4player.addAudioTrackListener(object : AudioTrackListener {
5 override fun onAudioTracksLoaded(tracks: List<AudioTrack>, reason: AudioTrackUpdateReason) {
6 // Populate your UI (language menu, etc.)
7 }
8 override fun onAudioTracksChange(selectedTrack: AudioTrack) {
9 // Update selected state in your UI
10 }
11 override fun onAudioTrackSwitching(isSwitching: Boolean) {
12 // Optional: show/hide a "switching" indicator
13 }
14 override fun onAudioTracksLoadedFailed(error: AudioTrackError) {
15 // Handle invalid id, player not ready, selection failure, etc.
16 }
17})

Switch audio track by ID

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

1val tracks = player.getAudioTracks()
2val target = tracks.firstOrNull() ?: return
3player.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:

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

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