Subtitles and captions
MKPlayer supports in-stream subtitles and captions from HLS and DASH manifests, as well as external subtitle tracks you add programmatically. You manage tracks through the player.subtitles API.
Subtitles have a kind of "subtitle". Captions (closed captions) have a kind of "caption". The API handles both the same way.
Prerequisites
You have an initialised MKPlayer instance with a source loaded. See Loading and playing content.
Enable and disable tracks
After a source loads, list available subtitle tracks and enable the one you want:
Each track in the list is an MKSubtitleTrack object with the following properties:
Add external subtitle tracks
You can add external subtitle tracks programmatically. Pass an MKSubtitleTrack object to player.subtitles.add():
Alternatively, include external tracks in the source configuration before calling player.load():
Remove a track
If the track is currently enabled, it is disabled before removal.
Style subtitles
You can change subtitle appearance at runtime using player.setSubtitleStyle(). Pass a style options object with any combination of the supported properties:
Supported style options:
Subtitle overlay
The player renders subtitles using a built-in overlay by default (enableSubtitleOverlay: true). To handle subtitle rendering yourself, disable the overlay and listen for cue events:
Then subscribe to cue events to receive subtitle text as it becomes active:
Note: the subtitle overlay is automatically disabled when the built-in UI (ui: true) is enabled. To use the overlay, keep ui disabled.