# How to programmatically enable or disable audio tracks on Roku

This article describes how you can use the AudioTrack API, a sub-API of the MediaTrack API, to enable or disable audio tracks. Implementing this functionality is a common use-case for developers who want to build their own UI to toggle audio languages on and off.

Once you have programmatically selected a track, you can set its `enabled` property (or method) to `true` or `false`. Because only one audio track can play at a time, enabling an audio track automatically disables all other audio tracks. Note that this does not apply to text tracks: multiple text tracks can be active at the same time.

## Usage

To set a preferred audio track, you can write a subroutine like `setAudioLanguage`. This subroutine accepts `language` as a string parameter. It then searches for the specified language in the audio tracks, and enables the track if it has a matching language.

```brightscript
sub setAudioLanguage(language as String)
  audioTracks = m.player.audioTracks
  for i = audioTracks.count() - 1 to 0 step -1
    if audioTracks[i].language = language then
      audioTracks[i].enabled = true
    else
      audioTracks[i].enabled = false
    end if
  end for
  ' Assignment of new roAssociativeArray is required, because Roku field values are copies, not references.
  ' Read more: https://developer.roku.com/en-gb/docs/developer-program/performance-guide/optimization-techniques.md#OptimizationTechniques-DataFlow
  m.player.audioTracks = audioTracks
end sub
```

## Related articles

* [How to programmatically detect audio tracks](https://docs-preview.optiview.dolby.com/pr-861/theoplayer/how-to-guides/roku/media-tracks/detect-audio-tracks.md)
