# How to programmatically detect audio track changes on Android

This article describes how you can use the AudioTrack API to detect audio track changes. An audio track "change" is triggered by enabling (or disabling) an audio track.

Implementing this functionality is a common use-case for developers who want to build their own UI, and annotate the audio track that is currently active.

## Usage

The implementation of the Android SDK applies to all Android-based platforms, including Android TV and Fire TV.

The Android SDK exposes the AudioTrack API through [`player.getAudioTracks()`](https://docs-preview.optiview.dolby.com/pr-860/theoplayer/v11/api-reference/android/com/theoplayer/android/api/player/Player#getAudioTracks\(\)). This `getAudioTracks()` method returns a [`MediaTrackList`](https://docs-preview.optiview.dolby.com/pr-860/theoplayer/v11/api-reference/android/com/theoplayer/android/api/player/track/mediatrack/MediaTrackList) that inherits from the [`TrackList`](https://docs-preview.optiview.dolby.com/pr-860/theoplayer/v11/api-reference/android/com/theoplayer/android/api/player/track/TrackList). This `TrackList` dispatches the events from the [`AudioTrackListEventTypes`](https://docs-preview.optiview.dolby.com/pr-860/theoplayer/v11/api-reference/android/com/theoplayer/android/api/event/track/mediatrack/audio/list/AudioTrackListEventTypes). The `AudioTrackListEventTypes` contains the [`TRACKLISTCHANGE`](https://docs-preview.optiview.dolby.com/pr-860/theoplayer/v11/api-reference/android/com/theoplayer/android/api/event/track/mediatrack/audio/list/AudioTrackListEventTypes#TRACKLISTCHANGE) event, as well as the `ADDTRACK` and `REMOVETRACK` event.

The code below allows you to detect audio track changes.

```kotlin
player.audioTracks.addEventListener(AudioTrackListEventTypes.TRACKLISTCHANGE) { event ->
    val track = event.track
    println("${track.label}, ${track.language}, ${track.isEnabled}")
}
```

The properties of a media `track` (e.g. `enabled`, `language`) are described in the [`MediaTrack`](https://docs-preview.optiview.dolby.com/pr-860/theoplayer/v11/api-reference/android/com/theoplayer/android/api/player/track/mediatrack/MediaTrack) and [`Track`](https://docs-preview.optiview.dolby.com/pr-860/theoplayer/v11/api-reference/android/com/theoplayer/android/api/player/track/Track) API references.

## Related articles

Are you reading this article because you are interested in audio tracks? Continue reading below.

* [How to programmatically detect audio tracks](https://docs-preview.optiview.dolby.com/pr-860/theoplayer/how-to-guides/android/media-tracks/detect-audio-tracks.md)
* [How to programmatically enable or disable audio tracks](https://docs-preview.optiview.dolby.com/pr-860/theoplayer/how-to-guides/android/media-tracks/enable-disable-audio-tracks.md)

Are you reading this article because you are implementing a custom UI? Then you will find the following articles interesting:

* [How to build a chromeless UI](https://docs-preview.optiview.dolby.com/pr-860/theoplayer/how-to-guides/android/ui/build-chromeless-ui.md)
* [How to detect video track quality changes](https://docs-preview.optiview.dolby.com/pr-860/theoplayer/how-to-guides/android/media-tracks/detect-video-track-quality-changes.md)
* [How to detect text track changes](https://docs-preview.optiview.dolby.com/pr-860/theoplayer/how-to-guides/android/text-tracks/detect-text-track-changes.md)
