# Subtitle

ByteArk Player SDK for iOS supports subtitles embedded in the HLS manifest. Viewers can pick a subtitle through the player UI or via the API.

# Select a subtitle via API

// List all subtitles
let subtitles: [ByteArkPlayerMediaTrack] = player.subtitleTracks
// Current subtitle
let current: ByteArkPlayerMediaTrack? = player.subtitleTrack
// Select a subtitle
player.setSubtitleTrack(subtitles[0])
// Disable subtitles
player.setSubtitleTrack(nil)
1
2
3
4
5
6
7
8
9
10
11

# Receive subtitle-change events

override func playbackSubtitleTrackChanged(
  player: ByteArkPlayer,
  subtitleTrack: ByteArkPlayerMediaTrack?
) {
  super.playbackSubtitleTrackChanged(player: player, subtitleTrack: subtitleTrack)
  // Subtitle changed
}
1
2
3
4
5
6
7

# Subtitle appearance

Three appearance settings are configured on ByteArkPlayerConfigBuilder and fixed when the configuration is built. They control how subtitles are drawn, not which track plays (use setSubtitleTrack(_:) for that).

let config = try ByteArkPlayerConfigBuilder(licenseKey: "<YOUR_LICENSE_KEY>")
  .item(item)
  .customSubtitle(true)                 // render subtitles in the SDK's own overlay
  .subtitleSize(.large)                 // subtitle text size
  .subtitlePaddingBottomPercentage(12)  // lift subtitles from the bottom edge
  .build()
1
2
3
4
5
6
Builder method Type Default Description
.customSubtitle(_:) Bool false Render cue text in the SDK's own overlay instead of the engine's native caption drawing. Available with the default AVFoundation playback engine.
.subtitleSize(_:) ByteArkPlayerSubtitleSize .medium Subtitle text size as a percentage of the video-frame height, so captions scale with the player rather than the screen.
.subtitlePaddingBottomPercentage(_:) Int 10 Lift subtitles from the bottom edge by a percentage of the video-frame height. Applies to native and custom subtitles.

ByteArkPlayerSubtitleSize values, smallest to largest: .minimum, .extraTiny, .tiny, .extraSmall, .small, .medium, .large, .extraLarge, .maximum.