# How to programmatically detect text track changes on iOS

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 iOS SDK applies to all iOS-based platforms, including iPadOS and tvOS.

The iOS SDK exposes the TextTrack API through [`player.textTracks`](https://docs-preview.optiview.dolby.com/pr-863/theoplayer/v11/api-reference/ios/Classes/THEOplayer#/s:13THEOplayerSDK0A0C10textTracksAA13TextTrackList_pvp). This `textTracks` property is a [`TextTrackList`](https://docs-preview.optiview.dolby.com/pr-863/theoplayer/v11/api-reference/ios/Protocols/TextTrackList). This `TextTrackList` dispatches the events from the [`TextTrackListEventTypes`](https://docs-preview.optiview.dolby.com/pr-863/theoplayer/v11/api-reference/ios/Structs/TextTrackListEventTypes). The `TextTrackListEventTypes` contains the [`CHANGE`](https://docs-preview.optiview.dolby.com/pr-863/theoplayer/v11/api-reference/ios/Structs/TextTrackListEventTypes#/s:13THEOplayerSDK23TextTrackListEventTypesV6CHANGEAA0F4TypeCyAA0d6ChangeF0CGvpZ) event, as well as the `ADD_TRACK` and `REMOVE_TRACK` event.

The code below allows you to detect text track changes.

```swift
player?.textTracks.addEventListener(type: TextTrackListEventTypes.CHANGE, listener: { event in
    let track: TextTrack = event.track as! TextTrack
    let isEnabled = track.mode == .showing
    print(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-863/theoplayer/v11/api-reference/ios/Protocols/TextTrack) and [`Track`](https://docs-preview.optiview.dolby.com/pr-863/theoplayer/v11/api-reference/ios/Protocols/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-863/theoplayer/how-to-guides/ios/text-tracks/detect-text-tracks.md)
* [How to dynamically change the visible captions](https://docs-preview.optiview.dolby.com/pr-863/theoplayer/how-to-guides/ios/text-tracks/change-visible-captions.md)
* [How to programmatically enable or disable text tracks](https://docs-preview.optiview.dolby.com/pr-863/theoplayer/how-to-guides/ios/text-tracks/enable-disable-text-tracks.md)
* [How to insert subtitles](https://docs-preview.optiview.dolby.com/pr-863/theoplayer/how-to-guides/ios/text-tracks/insert-subtitles.md)

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