# How to programmatically detect text track changes on Android

This article describes how you can use the TextTrack API to detect text track changes. A text track "change" is triggered by enabling (or disabling) a subtitle or closed captions track.

Implementing this functionality is a common use-case for developers who want to build their own UI, and annotate the subtitle (or closed captions) 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 TextTrack API through [`player.getTextTracks()`](https://docs-preview.optiview.dolby.com/pr-861/theoplayer/v11/api-reference/android/com/theoplayer/android/api/player/Player#getTextTracks\(\)). This `getTextTracks()` method returns a [`TextTrackList`](https://docs-preview.optiview.dolby.com/pr-861/theoplayer/v11/api-reference/android/com/theoplayer/android/api/player/track/texttrack/TextTrackList) that inherits from the [`TrackList`](https://docs-preview.optiview.dolby.com/pr-861/theoplayer/v11/api-reference/android/com/theoplayer/android/api/player/track/TrackList). This `TrackList` dispatches the events from the [`TextTrackListEventTypes`](https://docs-preview.optiview.dolby.com/pr-861/theoplayer/v11/api-reference/android/com/theoplayer/android/api/event/track/texttrack/list/TextTrackListEventTypes). The `TextTrackListEventTypes` contains the [`TRACKLISTCHANGE`](https://docs-preview.optiview.dolby.com/pr-861/theoplayer/v11/api-reference/android/com/theoplayer/android/api/event/track/texttrack/list/TextTrackListEventTypes#TRACKLISTCHANGE) event, as well as the `ADDTRACK` and `REMOVETRACK` event.

The code below allows you to detect text track changes.

```kotlin
player.textTracks.addEventListener(TextTrackListEventTypes.TRACKLISTCHANGE) { event ->
    val track = event.track
    val isEnabled = track.mode == TextTrackMode.SHOWING
    println("${track.label}, ${track.kind}, ${track.type}, $isEnabled")
}
```

The properties of a text `track` (e.g. `mode`, `kind`) are described in the [`TextTrack`](https://docs-preview.optiview.dolby.com/pr-861/theoplayer/v11/api-reference/android/com/theoplayer/android/api/player/track/texttrack/TextTrack) and [`Track`](https://docs-preview.optiview.dolby.com/pr-861/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 subtitles and closed captions? Continue reading below.

* [How to programmatically detect text tracks](https://docs-preview.optiview.dolby.com/pr-861/theoplayer/how-to-guides/android/text-tracks/detect-text-tracks.md)
* [How to dynamically change the visible captions](https://docs-preview.optiview.dolby.com/pr-861/theoplayer/how-to-guides/android/text-tracks/change-visible-captions.md)
* [How to programmatically enable or disable text tracks](https://docs-preview.optiview.dolby.com/pr-861/theoplayer/how-to-guides/android/text-tracks/enable-disable-text-tracks.md)
* [How to insert subtitles](https://docs-preview.optiview.dolby.com/pr-861/theoplayer/how-to-guides/android/text-tracks/insert-subtitles.md)

Refer to [how to track ID3 cues](https://docs-preview.optiview.dolby.com/pr-861/theoplayer/how-to-guides/android/text-tracks/track-id3-cues.md) if you are interested in timed metadata (ID3, emsg, EventStream, `EXT-X-DATERANGE`, ...).

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-861/theoplayer/how-to-guides/android/ui/build-chromeless-ui.md)
* [How to detect video track quality changes](https://docs-preview.optiview.dolby.com/pr-861/theoplayer/how-to-guides/android/media-tracks/detect-video-track-quality-changes.md)
* [How to detect audio track changes](https://docs-preview.optiview.dolby.com/pr-861/theoplayer/how-to-guides/android/media-tracks/detect-audio-track-changes.md)
