# How to track ID3 cues and tags on iOS

[ID3](https://en.wikipedia.org/wiki/ID3) is a type of metadata which can be inserted in HTTP live streams. Once an ID3 cue is inserted, it is added to a THEOplayer text track.

Developers commonly track ID3 cues because they want to introduce a certain behavior depending on the metadata contained by the ID3 cues, for example:

* to schedule advertisements dynamically by using information passed on by the ID3 metadata;
* to overlay certain text on top of the player (e.g. the score of a football match).

The demo at <https://demo.theoplayer.com/audio-id3-metadata> demonstrates a usage of ID3 metadata. Just before the song changes, an `enter` event is dispatched. The song information (title, album, etc.) is contained within this `enter` event, and can be used to update the UI.

This article describes how you can listen for timed metadata events, and how you can track the `enter` event.

## Listening for timed metadata events

Listen for the `CUE_CHANGE` event of a [`TextTrack`](https://docs-preview.optiview.dolby.com/pr-863/theoplayer/v11/api-reference/ios/Protocols/TextTrack).

```swift
let cueChangeListener = { (event: CueChangeEvent) in
    // do something with the cues
}

let handleTrackCreation = { (event: AddTrackEvent) in
    if let textTrack = event.track as? TextTrack {
        _ = textTrack.addEventListener(type: TextTrackEventTypes.CUE_CHANGE, listener: cueChangeListener)
    }
}

_ = player.textTracks.addEventListener(type: TextTrackListEventTypes.ADD_TRACK, listener: handleTrackCreation)
```

## Tracking the enter event

The `enter` event, which is part of the TextTrack API, maps to the moment in time when the ID3 cue becomes relevant.

```swift
let enterListener = { (event: EnterCueEvent) in
    // do something with the cue
}

let handleTrackCreation = { (event: AddTrackEvent) in
    if let textTrack = event.track as? TextTrack {
        _ = textTrack.addEventListener(type: TextTrackEventTypes.ENTER_CUE, listener: enterListener)
    }
}

_ = player.textTracks.addEventListener(type: TextTrackListEventTypes.ADD_TRACK, listener: handleTrackCreation)
```

## Resources

* <https://demo.theoplayer.com/audio-id3-metadata>: a demo which illustrates the use of ID3 in production.
* <http://id3.org/>: ID3.org home page.
* <https://en.wikipedia.org/wiki/ID3>: Wikipedia - ID3.
* <https://dev.w3.org/html5/html-sourcing-inband-tracks/>: Sourcing In-band Media Resource Tracks from Media Containers into HTML.

## Related articles

* [How to detect active text track cues](https://docs-preview.optiview.dolby.com/pr-863/theoplayer/how-to-guides/ios/text-tracks/detect-active-text-track-cues.md)
* [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)
