Add Subtitles to Mini Drama Player
Mini Drama Player can display subtitles from three sources: subtitles returned with the episode's media information, subtitle tracks declared in a Master M3U8 playlist, and subtitle files your mini app provides. Available tracks appear in the player's subtitle menu, where viewers can choose a language or turn subtitles off.
Prerequisites
- You have integrated Mini Drama Player.
- Your subtitle files exist. The player doesn't generate subtitles.
- Subtitle URLs are accessible from the TikTok app, with CORS configured for cross-origin requests.
Supported formats
External subtitle files can be WebVTT, SRT, ASS, or SSA. For ASS and SSA, the player displays text only, without complex layout, effects, or styling. Subtitle tracks in a Master M3U8 are parsed by the HLS engine, so this format list doesn't apply to them.
Choose a subtitle source
The following table lists how to configure each source:
Source | Configuration |
Subtitles returned with media information | Set |
Tracks declared in a Master M3U8 | Use the HLS plugin and set |
Subtitle files your mini app provides | Set |
Automatic subtitles replace Subtitle.list. A non-empty Subtitle.list takes precedence over Master playlist tracks.
Display subtitles from media information
This is the most common setup for mini dramas.
- Upload one subtitle file per language with Upload Mini Drama Subtitles, linked to the episode's video.
- When you create the player, set
autoSubtitle: trueand register the subtitle plugin withSubtitle:
const VePlayer = await TTMinis.getPlayer();
const playerSdkIns = new VePlayer({
id: 'player-container',
albumId: videoInfo.album_id,
episodeId: videoInfo.episode_id,
autoSubtitle: true,
Subtitle: {
isDefaultOpen: true,
isShowIcon: true,
},
});The player parses subtitles after it retrieves media information, so the subtitle list updates asynchronously. Don't assume it's ready immediately after you create the player.
The player converts each subtitle's language or language_id to the language's native name for display, such as English, 简体中文, or 日本語. See Language display names.
Display subtitles from a Master M3U8
For a Master playlist that declares subtitle tracks, register the subtitle plugin and leave autoSubtitle disabled:
const VePlayer = await TTMinis.getPlayer();
const playerSdkIns = new VePlayer({
id: 'player-container',
url: masterUrl,
streamType: 'hls',
enableMobileHlsPlugin: true,
Subtitle: {}, // Register the subtitle plugin with default settings
});Tracks appear in the menu after the playlist is parsed. To hide subtitles until the viewer selects a track, set Subtitle: { isDefaultOpen: false }.
Provide your own subtitle files
To display subtitle files your mini app hosts, set Subtitle.list:
const playerSdkIns = new VePlayer({
// Other player options
autoSubtitle: false,
Subtitle: {
isDefaultOpen: true,
list: [
{
id: 'sub-zh',
language: 'zh-CN',
text: '简体中文',
url: 'https://example.com/episode-1.zh.vtt',
isDefault: true,
},
{
id: 'sub-en',
language: 'en-US',
text: 'English',
url: 'https://example.com/episode-1.en.vtt',
},
],
},
});Configuration reference
autoSubtitle
Property | Type | Default |
|
|
|
If true, the player converts the subtitle_info_list returned with media information into the subtitle list.
formatAutoSubtitleItem
Property | Type | Default |
|
|
|
A synchronous callback that runs for each automatic subtitle. It applies only to subtitles from media information, not to Subtitle.list or Master playlist tracks. Return a value directly, not a Promise.
The callback receives the following parameters:
Parameter | Type | Description |
|
| The raw subtitle item returned by the server. |
|
| The item's zero-based position in the original list. |
Each item object can contain the following fields:
Field | Type | Description |
|
| The subtitle ID. |
|
| The language tag, such as |
|
| The language ID, such as |
|
| The subtitle format, such as |
|
| The URL of the subtitle file. |
|
| The subtitle source, such as |
|
| The subtitle status, such as |
|
| The subtitle title. Used as the display name when the language isn't in the mapping table. |
|
| The subtitle tag. |
|
| The file ID. |
|
| The storage URI. |
|
| The video ID. |
The return value controls how the player handles the item:
Return value | Behavior |
| Uses the value as the display name. |
| Keeps the default result. |
| Removes the item from the list. |
| Uses |
| Removes the item from the list. |
| Sets the sort order. Lower values appear first. Can be combined with |
| Selects the item by default. Can be combined with |
Subtitle
Subtitle: {} registers the subtitle plugin with default settings. When autoSubtitle is enabled, the server response populates list.
Property | Type | Default | Description |
|
|
| The subtitle list. Populated automatically when |
|
|
| If |
|
|
| If |
|
|
| The position of the button in the controls. |
|
|
| The order of the button. Lower values appear further right. |
|
| See the following table. | The subtitle style. |
|
| N/A | Custom menu labels. See Customize subtitle labels. |
style accepts the following properties:
Property | Type | Default | Description |
|
|
| If |
|
|
| The offset, in pixels, when subtitles follow the control bar. |
|
|
| If |
|
|
| The distance from the bottom of the video frame, as a percentage. |
|
|
| The text style. |
|
|
| The base font size for landscape video. |
|
|
| The base font size for portrait video. |
|
|
| The minimum font size on desktop. |
|
|
| The minimum font size on mobile. |
|
|
| The maximum number of lines. |
|
|
| The font color, as a hex or RGB value. |
Caution: style replaces the default style object instead of merging with it. If you set only style: { follow: true }, fitVideo isn't set, and subtitles move up when the controls appear. To keep the default fit, include fitVideo: true.
Each ISubTitleItem in list accepts the following properties:
Property | Type | Description |
|
| The subtitle ID. |
|
| The language tag. |
|
| The display name. |
|
| The URL of the subtitle file. |
|
| Inline subtitle content, in WebVTT or SRT format. |
|
| Structured subtitle content, used instead of a URL. |
|
| If |
const playerSdkIns = new VePlayer({
// Other player options
autoSubtitle: true,
Subtitle: {
isDefaultOpen: true,
isShowIcon: true,
style: {
follow: true,
fitVideo: true,
mode: 'stroke',
offsetBottom: 4,
line: 'double',
fontColor: '#fff',
},
},
});Language display names
For automatic subtitles, the player looks up language_id or language in a built-in table and displays the language's native name:
|
| Display name |
|
| 简体中文 |
|
| English |
|
| 日本語 |
|
| 한국어 |
|
| 中英双语 |
|
| Русский |
|
| Français |
|
| Português |
|
| Español |
|
| Tiếng Việt |
|
| Deutsch |
|
| Italiano |
|
| العربية |
|
| 繁體中文 |
|
| हिन्दी |
If the language isn't in the table, the player uses the first available value in this order: title, label, text, language, tag, then language_id. For the full language list, see BytePlus VOD subtitle languages.
Examples
Merge each example into your player configuration.
Hide subtitles until the viewer selects a track
autoSubtitle: true,
Subtitle: {
isDefaultOpen: false,
isShowIcon: true,
},Select a default language
isDefault chooses the default track. isDefaultOpen controls whether it's visible when playback starts. If more than one track is marked as default, the first one in the final list applies. If none is marked, the player selects the first track.
autoSubtitle: true,
formatAutoSubtitleItem: (item) => {
if (!item || typeof item !== 'object') return true;
// Select English by default
if (item.language === 'eng-US') {
return { isDefault: true };
}
return true;
},
Subtitle: { isDefaultOpen: true },To sort English first, remove machine-translated tracks, and select English by default:
formatAutoSubtitleItem: (item, index) => {
if (!item || typeof item !== 'object') return true;
if (item.source === 'MT') return false;
return {
order: item.language === 'eng-US' ? 0 : index + 1,
isDefault: item.language === 'eng-US',
};
},Select the viewer's language
navigator.language returns the WebView's language preference, which can differ from the phone's system language. The following example maps common language codes to subtitle tags. You can match on language_id instead, such as Number(item.language_id) === 1.
const SYSTEM_LANG_TO_SUBTITLE_LANGUAGE = {
'zh-hant': 'cmn-Hant-CN', // Traditional Chinese
zh: 'cmn-Hans-CN', // Simplified Chinese
en: 'eng-US',
ja: 'jpn-JP',
ko: 'kor-KR',
ru: 'rus-RU',
fr: 'fra-FR',
pt: 'por-PT',
es: 'spa-ES',
vi: 'vie-VN',
de: 'deu-DE',
it: 'ita-IT',
ar: 'ara-SA',
hi: 'hin-IN',
};
function getSystemSubtitleLanguage() {
const lower = (navigator.language || navigator.languages?.[0] || '').toLowerCase();
const iso = lower.split('-')[0];
if (iso === 'zh') {
const isHant = lower.includes('hant') || /\b(tw|hk|mo)\b/.test(lower);
return SYSTEM_LANG_TO_SUBTITLE_LANGUAGE[isHant ? 'zh-hant' : 'zh'];
}
return SYSTEM_LANG_TO_SUBTITLE_LANGUAGE[iso] ?? null;
}
const systemSubtitleLanguage = getSystemSubtitleLanguage();
const playerSdkIns = new VePlayer({
// Other player options
autoSubtitle: true,
formatAutoSubtitleItem: (item) => {
if (!item || typeof item !== 'object') return true;
if (
systemSubtitleLanguage !== null &&
typeof item.language === 'string' &&
item.language.toLowerCase() === systemSubtitleLanguage.toLowerCase()
) {
return { isDefault: true };
}
return true;
},
Subtitle: { isDefaultOpen: true },
});Show only SRT subtitles
autoSubtitle: true,
formatAutoSubtitleItem: (item, index) => {
if (!item || typeof item !== 'object') return false;
if (String(item.format || '').toLowerCase() !== 'srt') return false;
return { order: index };
},
Subtitle: { isDefaultOpen: true },Use the subtitle title as the display name
autoSubtitle: true,
formatAutoSubtitleItem: (item) => {
if (!item || typeof item !== 'object') return true;
return item.title || item.language;
},
Subtitle: {},Remove machine-translated subtitles and sort ASR subtitles first
autoSubtitle: true,
formatAutoSubtitleItem: (item, index) => {
if (!item || typeof item !== 'object') return true;
if (item.source === 'MT') return false;
return { order: item.source === 'ASR' ? 0 : index + 1 };
},
Subtitle: {},Show only specific languages
autoSubtitle: true,
formatAutoSubtitleItem: (item) => {
if (!item || typeof item !== 'object') return false;
const allowedLangs = ['cmn-Hans-CN', 'eng-US'];
if (!allowedLangs.includes(item.language)) return null;
return { label: item.title || item.language };
},
Subtitle: {},Control subtitles with the API
You can control subtitles from your own UI. The subtitle plugin must be registered with Subtitle: {}.
getSubtitleList()
Gets the current subtitle list. Returns [] if the plugin is unavailable or subtitles aren't ready. Master playlist tracks have source: 'hls'.
const list = playerSdkIns.getSubtitleList();
// [
// { id: 'sub-zh', language: 'cmn-Hans-CN', text: '简体中文', url: 'https://example.com/zh.vtt' },
// { id: 'sub-en', language: 'eng-US', text: 'English', url: 'https://example.com/en.vtt' },
// ]Master playlist tracks don't expose playback URLs or internal track indexes. Switch them by id. Their text and label contain the original names, not names formatted by Subtitle.label.
type ISubtitleLabelValue = string | number | Record<string, string | number>;
// Master playlist fields in ISubTitleItem
interface ISubTitleItem {
source?: 'config' | 'hls';
id?: string | number;
language?: string | number;
text?: ISubtitleLabelValue; // Original subtitle name
label?: ISubtitleLabelValue; // Compatibility label field
isDefault?: boolean; // Whether this is the default track
forced?: boolean; // Whether this is a forced track
characteristics?: string; // Track characteristics, such as accessibility traits
}Read the list again after switching episodes. Don't reuse IDs from a previous episode.
switchSubtitle(subtitle)
Switches to a subtitle. Returns a Promise<void>.
async function selectSubtitle(id) {
try {
await playerSdkIns.switchSubtitle({ id });
} catch (error) {
console.warn('Subtitle switch failed', error);
}
}Parameter | Type | Description |
|
| The subtitle ID. Required if |
|
| The language tag. Must match exactly one track in the current list. |
An exact id match takes precedence. In hls.js mode, the promise resolves after the engine confirms the switch and rejects if the switch fails.
showSubtitle()
Shows subtitles. Restores the last selected subtitle, or selects the first one if none was selected.
playerSdkIns.showSubtitle();hideSubtitle()
Hides subtitles. The subtitle list is kept, so you can show it again with showSubtitle() or switchSubtitle().
playerSdkIns.hideSubtitle();Example: Custom English subtitle button
async function selectEnglishSubtitle() {
const list = playerSdkIns.getSubtitleList();
const target = list.find((item) =>
['eng-us', 'en-us', 'en'].includes(String(item.language).toLowerCase())
);
if (!target || target.id == null) return;
try {
await playerSdkIns.switchSubtitle({ id: target.id });
} catch (error) {
console.warn('Subtitle switch failed. Refresh the subtitle list.', error);
}
}Subtitle events
The following events report subtitle list and selection changes for Master playlists and native HLS. Register them with playerSdkIns.on(VePlayer.Events.EVENT_NAME, callback), and check playbackSessionId before you use the payload.
Event | Payload | Description |
|
| The subtitle list was updated. |
|
| A subtitle switch was submitted. |
|
| A subtitle switch was confirmed. |
interface IHlsSubtitleTracksUpdatedEvent {
playbackSessionId: string;
playbackEngine: HlsPlaybackEngine;
tracks: ReadonlyArray<ISubTitleItem>;
}
interface IHlsSubtitleTrackSwitchEvent {
playbackSessionId: string;
playbackEngine: HlsPlaybackEngine;
from: string | number | null; // Subtitle ID. null means subtitles were off.
to: string | number | null;
track?: ISubTitleItem;
}Customize subtitle labels
Subtitle.label sets the menu labels for every subtitle source. Keys must match the language tags that getSubtitleList() returns. For example, eng-US and en-US are different keys, and en doesn't match eng-US.
Subtitle: {
isDefaultOpen: true,
isShowIcon: true,
label: {
map: {
language: {
'cmn-Hans-CN': { text: '简体中文' },
'cmn-Hant-CN': { text: '繁體中文' },
'eng-US': { text: 'English' },
'zh-CN': { text: '简体中文' },
en: { text: 'English' },
'pt-BR': { text: 'Português (Brasil)' },
},
},
formatter: ({ defaultLabel, item }) =>
item.forced ? `${defaultLabel} (Forced)` : defaultLabel,
},
},The map also accepts id and original text keys. The player matches in this order: id, full language tag, base language, then original name. For example, en-US falls back to en. formatter is synchronous and returns the final label.
Labels change only the VePlayer menu. They don't change subtitle content, the subtitle language, or the iOS system subtitle menu. To filter, sort, or select default tracks, use formatAutoSubtitleItem instead.
Localize subtitle labels
To translate labels into the player's UI language, set textKey to a key in the player's languages dictionary. text is the fallback when no translation exists.
lang: 'zh',
languages: {
zh: { SUBTITLE_EN: '英语' },
en: { SUBTITLE_EN: 'English' },
},
Subtitle: {
label: {
map: {
language: {
en: { textKey: 'SUBTITLE_EN', text: 'English' },
'eng-US': { textKey: 'SUBTITLE_EN', text: 'English' },
},
},
},
},Troubleshooting
Subtitles don't appear
This happens when the subtitle plugin isn't registered, the list is empty, or subtitles are hidden.
To resolve this, confirm that you set Subtitle, then check whether getSubtitleList() returns items for the current episode. If the list is empty, check the subtitle's link to the video, the Master playlist declarations, and your formatAutoSubtitleItem filters. If the list has items, check whether subtitles are hidden, whether a cue covers the current playback time, and whether the subtitle request succeeded.
Custom labels don't apply
This happens when the label keys don't match the subtitle IDs or language tags, or when the labels are confused with the player UI language.
To resolve this, use the exact id or language values that getSubtitleList() returns. Labels affect only the VePlayer menu, not the iOS system menu.