Play HLS and Transcoded Videos
Play transcoded outputs, HLS streams, Master M3U8 playlists with multiple qualities, multi-audio streams, and H.265 video in Mini Drama Player. By default, the player plays MP4 (H.264). The configurations on this page select other outputs and enable HLS features.
Prerequisites
- You have integrated Mini Drama Player.
- To play transcoded outputs, you have transcoded the episode with Create a Mini Drama Transcoding Task.
Play transcoded videos
To play a specific transcoded output, pass transcodeParam when you create the player.
transcodeParam requires TikTok 46.7.0 or later. In earlier versions, the player ignores it and uses the default output. To detect support, call TTMinis.canIUse('getDramaInfo.transcodeParam'):
const canUseTranscodeParam = TTMinis.canIUse('getDramaInfo.transcodeParam');
if (!canUseTranscodeParam) {
// The player uses the default output and ignores transcodeParam
}transcodeParam
All transcodeParam fields are optional strings. They correspond to the request parameters of BytePlus GetPlayInfo.
Field | Description | Example |
| The container format. |
|
| The video codec. |
|
| The definition to return. If omitted, every definition that matches the other fields is returned. |
|
| The stream file type. |
|
| Whether to return sprite image information. |
|
| Whether to return live comment mask information. |
|
| The identifier required for private encrypted playback. | Generated at runtime |
| The audio quality. |
|
| The private encryption key-encryption key (KEK). | Generated at runtime |
| Identifies the web player as the source. |
|
Warning: Generate unionInfo and drmKek at runtime through your private encryption process. Don't write them into source code, logs, or persistent storage.
Create a player with transcoding parameters
The following example omits transcodeParam.definition, so the server returns every HLS H.264 definition. defaultDefinition selects only the starting definition.
const VePlayer = await TTMinis.getPlayer();
const transcodeParam = {
format: 'hls',
codec: 'H264',
};
const playerSdkIns = new VePlayer({
id: 'player-container',
vid: videoInfo.vid,
albumId: videoInfo.album_id,
episodeId: videoInfo.episode_id,
defaultDefinition: '720p',
transcodeParam,
enableMp4MSE: true,
});If you specify a definition that doesn't exist, BytePlus VOD can return a fallback. For example, if only an MP4 output exists, a request for hls can return the MP4.
Switch episodes with transcoding parameters
Pass transcodeParam to playNext:
await playerSdkIns.playNext({
vid: nextEpisode.vid,
albumId: nextEpisode.album_id,
episodeId: nextEpisode.episode_id,
transcodeParam: {
format: 'hls',
codec: 'H264',
},
});playNext handles transcodeParam as follows:
- Omitted: The new episode inherits the current parameters.
- A new object: Replaces the current parameters entirely. It doesn't merge with the previous episode's fields.
undefined: Clears the parameters. Later requests don't include the field.{}: Sends an empty object, which isn't the same as clearing the parameters.
Switch definitions
If the episode has several definitions and you didn't set transcodeParam.definition, the player can switch between the definitions the server returns. Read the list with getDefinitionList() after the READY event, and switch with changeDefinition():
playerSdkIns.on(VePlayer.Events.READY, () => {
const definitions = playerSdkIns.getDefinitionList();
// Switch only to a definition in the list
if (definitions.some((item) => item.definition === '720p')) {
playerSdkIns.changeDefinition('720p');
}
});
playerSdkIns.on(VePlayer.Events.DEFINITION_CHANGE, ({ to }) => {
console.log('Current definition:', to.definition);
});If transcodeParam.definition names a definition, the server usually returns only that definition or its fallback, so you can't switch to others. If defaultDefinition doesn't match any returned definition, the player uses the first one in the list.
The player's definition menu opens from the upper-right corner. To choose a menu style, set panel.mode:
panel: {
mode: 0, // Default
},
| Style |
| ![]() |
| ![]() |
| ![]() |
Preload transcoded videos
setPreloadList and addPreloadList accept transcodeParam. To reuse the cache, use the same episodeId and effective transcodeParam for preloading and playback, and set enableMp4MSE: true on the player. defaultDefinition selects which URL to preload.
await VePlayer.setPreloadList([
{
vid: nextEpisode.vid,
albumId: nextEpisode.album_id,
episodeId: nextEpisode.episode_id,
defaultDefinition: '720p',
transcodeParam,
},
]);For more about preloading, see Optimize Mini Drama Playback Startup.
Play HLS videos
The player plays HLS (M3U8). If the original upload is HLS, it plays without extra configuration. For a transcoded HLS output, pass transcodeParam:
const VePlayer = await TTMinis.getPlayer();
const playerSdkIns = new VePlayer({
id: 'player-container',
vid: videoInfo.vid,
albumId: videoInfo.album_id,
episodeId: videoInfo.episode_id,
defaultDefinition: '720p',
transcodeParam: {
format: 'hls',
codec: 'H264',
},
});On Android and iOS, the player uses the native video element for HLS by default, and the browser selects the bitrate.
To use manual quality selection, multiple audio tracks, or the player's subtitle menu, set enableMobileHlsPlugin: true. The player uses the HLS plugin when the device supports MSE or ManagedMediaSource, and falls back to native playback otherwise.
const playerSdkIns = new VePlayer({
id: 'player-container',
vid: videoInfo.vid,
albumId: videoInfo.album_id,
episodeId: videoInfo.episode_id,
defaultDefinition: '720p',
enableMobileHlsPlugin: true,
});Load the HLS plugin early
Add the HLS plugin script to the <head> of your entry HTML, so the browser downloads it while parsing the page instead of when the player starts:
<script
defer
src="https://sf-unpkg.bytepluscdn.com/obj/byteplusfe-sg/sdk/@byteplus/veplayer/1.20.0/plugin/hlsjsPro.js"
></script>defer downloads the script during HTML parsing and runs it afterward. Place the tag before your application entry script, and initialize the player after the plugin runs. Use a plugin version that matches the VePlayer SDK your mini app loads.
Enable progressive loading
With hlsjs.progressive: true, hls.js appends segment data to the buffer before the download finishes, which can shorten the wait for the first frame. Enable it only for unencrypted HLS. Defaults vary between versions, so set it explicitly.
const playerSdkIns = new VePlayer({
id: 'player-container',
vid: videoInfo.vid,
albumId: videoInfo.album_id,
episodeId: videoInfo.episode_id,
enableMobileHlsPlugin: true,
hlsjs: {
progressive: true,
},
});Play Master M3U8 videos
For a Master M3U8 that contains several quality levels, the player supports adaptive bitrate (ABR) selection, manual quality selection from its built-in menu, and declared subtitle tracks. For subtitles, see Add Subtitles to Mini Drama Player.
const VePlayer = await TTMinis.getPlayer();
const playerSdkIns = new VePlayer({
id: 'player-container',
vid: videoInfo.vid,
albumId: videoInfo.album_id,
episodeId: videoInfo.episode_id,
enableMobileHlsPlugin: true,
defaultDefinition: 'auto',
autoBitrateOpts: {
enable: true,
engine: 'hlsjs',
startWithAuto: true,
showRealDefinition: true,
},
Subtitle: {
isDefaultOpen: true,
isShowIcon: true,
},
});When hls.js plays a Master with more than one level, it uses ABR by default, even without autoBitrateOpts, and the quality menu selects Auto. Auto mode adapts quality during playback. It doesn't guarantee the highest quality or a specific resolution for the first frame.
Set the starting level
To choose the first level hls.js loads, set hlsjs.startLevel. It doesn't leave Auto mode, so later segments can still switch quality. For example, if level 0 is 540p, the player can start at 540p and later switch to 1080p.
hlsjs: {
startLevel: 0, // Level index 0. Quality stays adaptive afterward.
},Option | Type | Description |
|
|
|
Level indexes start at 0 and depend on the levels hls.js parses, so index 1 isn't necessarily 720p. To see the mapping, call getHlsLevels() after HLS_LEVELS_UPDATED. If you don't know the mapping before you create the player, keep -1. startLevel has no effect during native HLS playback. For details, see hls.js startLevel.
defaultDefinition and startWithAuto don't select a Master level. Calling setHlsLevel() during playback switches to manual mode instead of setting the starting level.
Configure adaptive bitrate
autoBitrateOpts is optional. It explicitly selects the ABR engine and controls the Auto label.
Parameter | Default | Description |
|
| If |
|
| Set to |
|
| Starts in SDK definition Auto mode. Not needed for hls.js Auto mode and doesn't select a starting level. |
|
| If |
| Follows the player language | A custom Auto label, such as Smart. |
To localize the Auto label, define DEFINITION_AUTO in languages and omit autoDefinitionText:
lang: 'zh',
languages: {
zh: { DEFINITION_AUTO: '智能' },
en: { DEFINITION_AUTO: 'Auto' },
},Customize quality labels
To replace labels such as 720p with your own text, set hlsLevelLabel. Keys are the standard labels derived from the video's shorter dimension, including for portrait video.
hlsLevelLabel: {
map: {
'480p': { text: 'SD' },
'720p': { text: 'HD' },
'1080p': { text: 'Full HD' },
},
// Optional: customize the final label
formatter: ({ defaultLabel, level }) =>
level.videoRange === 'PQ' ? `${defaultLabel} HDR` : defaultLabel,
},Labels change only the menu text, not level indexes or switching. To localize them, use textKey with languages:
lang: 'zh',
languages: {
zh: { QUALITY_HD: '高清' },
en: { QUALITY_HD: 'HD' },
},
hlsLevelLabel: {
map: {
'720p': { textKey: 'QUALITY_HD', text: '720p' },
},
},

Build a custom quality menu
To build your own menu, listen for HLS_LEVELS_UPDATED, render the levels, and switch with setHlsLevel:
let levelState = null;
function updateLevels() {
const state = playerSdkIns.getHlsLevelState();
levelState = state.ready ? state : null;
// Render the menu from levelState.levels, keeping each item's index
}
playerSdkIns.on(VePlayer.Events.HLS_LEVELS_UPDATED, updateLevels);
updateLevels();
function selectLevel(index) {
if (!levelState) return;
playerSdkIns.setHlsLevel(index, {
playbackSessionId: levelState.playbackSessionId,
});
}To hide the built-in quality menu, add sdkDefinitionPlugin to ignores:
ignores: ['sdkDefinitionPlugin'],Use setHlsLevel for levels within a Master. If transcoding returns separate URLs per definition, use getDefinitionList() and changeDefinition() instead. A manual selection stops ABR. Use the returned index, not an assumed value. Listen for HLS_LEVEL_SWITCHED to update the selected state, and refresh the list after switching episodes.
API | Parameters and return value | Description |
| None. Returns | Returns the current levels, or |
| None. Returns | Returns the levels, readiness, active levels, and session ID. Check |
| A returned | Enters manual mode and submits a switch. Throws synchronously on failure. |
interface IHlsLevel {
index: number; // Level index within this playback session
bitrate: number; // Peak bitrate, in bits per second
averageBitrate?: number; // Average bitrate, in bits per second
width?: number; // Video width, in pixels
height?: number; // Video height, in pixels
frameRate?: number;
videoCodec?: string;
audioCodec?: string;
videoRange?: string; // Video dynamic range
name?: string; // Name declared in the manifest
}
interface IHlsLevelState {
playbackSessionId: string;
ready: boolean;
levels: IHlsLevel[];
currentLevel: number; // Current playback level. -1 when unknown.
loadLevel: number; // Current loading level. -1 when unknown.
nextLevel: number; // Next segment level. -1 when unknown.
manualLevel: number; // Manual level. -1 in Auto mode.
autoLevelEnabled: boolean;
autoLevelCapping: number; // Auto level cap. -1 when unset.
}
type HlsLevelSwitchMode = 'next-fragment' | 'smooth' | 'immediate';
interface IHlsLevelSwitchOptions {
mode?: HlsLevelSwitchMode; // Default: next-fragment
playbackSessionId?: string; // Rejects the switch if it doesn't match the current session
}The mode option controls how the switch happens:
next-fragment: Switches at the next segment.smooth: Keeps buffered content, so the change can appear later.immediate: Switches immediately and can briefly interrupt playback.
Level metadata doesn't include playback URLs or authentication data.
The following events report level changes. Check playbackSessionId before you use the payload.
Event | Payload | Description |
|
| The level list or state changed. Check |
|
| A switch was submitted. |
|
| A switch was confirmed. |
interface IHlsLevelSwitchEvent {
playbackSessionId: string;
from: number; // Previous level
to: number; // Target or confirmed level
reason: 'manual' | 'abr';
abrEngine: ResolvedAbrEngine;
level?: IHlsLevel;
}Restore Auto mode
When the viewer selects Auto, call setHlsAbrMode('auto'). You can also cap the bitrate that ABR selects. A cap doesn't select a fixed level or exit manual mode.
const { capabilities } = playerSdkIns.getHlsAbrState();
if (capabilities.restoreAuto) {
playerSdkIns.setHlsAbrMode('auto');
}
// Optional: cap the bitrate for automatic selection, in bits per second
if (capabilities.bitrateCap) {
playerSdkIns.setHlsAbrLimit({
type: 'bitrate',
maxBitrate: 2500000, // 2.5 Mbps
});
// To clear the cap: playerSdkIns.setHlsAbrLimit(null);
}API | Parameters and return value | Description |
| None. Returns | Returns the ABR engine, Auto or manual mode, and supported controls. |
|
|
|
| None. Returns | Returns the cap, or |
| A cap object or | Sets or clears the cap. Throws synchronously on failure and keeps the previous cap. |
hls.js supports level and bitrate caps, not definition caps. maxLevel must be a valid index, maxBitrate is in bits per second, and maxDefinition is a definition identifier. Check capabilities before you call these methods.
type HlsPlaybackEngine = 'hlsjs' | 'veplayer-hls' | 'native' | 'none';
type HlsAbrEngine = 'hlsjs' | 'veplayer';
type ResolvedAbrEngine = HlsAbrEngine | 'native' | 'none';
type HlsAbrMode = 'auto' | 'manual';
interface IHlsAbrState {
playbackSessionId: string;
playbackEngine: HlsPlaybackEngine; // Actual playback engine
configuredEngine: HlsAbrEngine | null; // null when ABR configuration is disabled
engine: ResolvedAbrEngine; // Actual ABR decision engine
decisionSource: 'hls-levels' | 'definition-list' | 'native' | 'none';
available: boolean; // Whether the engine requirements are met
active: boolean; // Whether automatic selection is active
mode: HlsAbrMode;
currentLevel?: number; // Current hls.js level
currentDefinition?: string; // Current VePlayer ABR definition
reason?: HlsAbrUnavailableReason;
capabilities: IHlsAbrCapabilities;
}
interface IHlsAbrCapabilities {
levelList: boolean;
manualLevelSwitch: boolean;
restoreAuto: boolean;
levelCap: boolean;
bitrateCap: boolean;
definitionCap: boolean;
}
type IHlsAbrLimit =
| { type: 'level'; maxLevel: number }
| { type: 'bitrate'; maxBitrate: number }
| { type: 'definition'; maxDefinition: string }
| null;
type HlsAbrUnavailableReason =
| 'NOT_HLS'
| 'NOT_HLSJS_ENGINE'
| 'MANIFEST_NOT_READY'
| 'MULTI_LEVEL_MASTER_REQUIRED'
| 'DEFINITION_LIST_REQUIRED'
| 'ABR_MODULE_UNAVAILABLE'
| 'ABR_RUNTIME_UNAVAILABLE'
| 'LICENSE_UNAVAILABLE'
| 'NO_ABR_VARIANTS';Event | Payload | Description |
|
| The ABR engine was resolved. |
|
| The mode or state changed. |
|
| The cap changed. |
Handle HLS control errors
setHlsLevel, setHlsAbrMode, and setHlsAbrLimit throw synchronously, so wrap them in try/catch. switchSubtitle returns a promise, so use await with try/catch. Check HlsControlError.code to identify the cause. A missing subtitle plugin can throw a plain Error without a code.
declare class HlsControlError extends Error {
readonly code: HlsControlErrorCode;
constructor(code: HlsControlErrorCode, message: string);
}
type HlsControlErrorCode =
| 'HLS_MANIFEST_NOT_READY'
| 'HLS_ENGINE_UNSUPPORTED'
| 'HLS_LEVEL_OUT_OF_RANGE'
| 'HLS_PLAYBACK_SESSION_EXPIRED'
| 'HLS_ABR_UNAVAILABLE'
| 'HLS_ABR_LIMIT_UNSUPPORTED'
| 'HLS_SUBTITLE_TRACK_NOT_FOUND'
| 'HLS_SUBTITLE_TRACK_AMBIGUOUS'
| 'HLS_SUBTITLE_SWITCH_FAILED'
| 'HLS_SUBTITLE_SWITCH_TIMEOUT';If the manifest isn't ready, wait for a list update. If the index is invalid or the session expired, refresh the list. Hide controls that capabilities doesn't support. If a subtitle language matches more than one track, select by id.
Play multi-audio HLS videos
The player can switch between audio tracks in a multi-audio HLS stream, such as one video dubbed for several languages.
The stream must be a Master playlist that declares multiple audio tracks with #EXT-X-MEDIA:TYPE=AUDIO. MP4 and single-audio HLS don't provide switchable tracks. transcodeParam.format: 'hls' requests an HLS URL but doesn't create a multi-audio output. The multi-audio asset must already exist in BytePlus VOD.
Enable multiple audio tracks on mobile
Set enableMobileHlsPlugin: true. Support depends on the device:
Platform | Condition | Behavior |
Android | The in-app browser supports MSE ( | Uses hls.js and supports switching. Native Android video doesn't expose |
iOS 17.1 and later |
| Uses hls.js through ManagedMediaSource. |
iOS earlier than 17.1 | N/A | Falls back to native HLS and switches through |
const VePlayer = await TTMinis.getPlayer();
const playerSdkIns = new VePlayer({
id: 'player-container',
vid: videoInfo.vid,
albumId: videoInfo.album_id,
episodeId: videoInfo.episode_id,
transcodeParam: {
format: 'hls',
codec: 'H264',
},
audioPreference: { lang: 'en' },
enableMobileHlsPlugin: true,
AudioTrackMobile: {
index: 2.6,
isShowIcon: true,
showNameSuffix: true,
},
});On hls.js, the player keeps the selected track across quality switches. Devices that don't meet the hls.js conditions fall back to native playback without affecting basic playback. If the runtime doesn't expose the audio track APIs, keep the default track and hide your custom selector instead of treating playback as failed.
Set the starting audio track
audioPreference selects the track when playback starts. Pass only the fields that identify the track. lang is usually enough. Add name when several tracks share a language:
audioPreference: { lang: 'en', name: 'Stereo' },langmatching isn't case sensitive.- All fields you pass must match.
- On native iOS, the player matches
id,lang, andname.namecorresponds toAudioTrack.label. - If no track matches, the player uses the manifest's default track without an error.
- After a quality switch, the player restores the viewer's last selection, then
audioPreference, then the manifest default. playNext()clears the previous selection and appliesaudioPreferenceto the new episode.
Configure the audio track button
The AudioTrackMobile plugin adds an audio track button in the upper-right corner of the player.
AudioTrackMobile: {
index: 2.6, // Position in the control bar. Lower values appear further left. Default: 2.6
isShowIcon: true, // Show the button. Default: true
showNameSuffix: true, // Append the source track name, such as "Japanese (Stereo AudioTrack1)"
},To keep the plugin but hide its button, such as when you build your own selector, set isShowIcon: false. To turn off the plugin, set AudioTrackMobile: false.
Audio track APIs
API or event | Description |
| Returns the audio tracks for the current video, or |
| Returns the active track, or |
| Switches to a track. Pass an item returned by |
| Fires when the track list is ready or changes. The payload contains |
| Fires after a switch completes. The payload contains |
interface AudioTrackInfo {
id: number; // Track index in the list
name: string; // HLS NAME on hls.js, or AudioTrack.label on native iOS
default: boolean; // Whether the manifest marks this as the default track
selected: boolean; // Whether this is the active track
lang?: string; // BCP 47 language code
assocLang?: string; // HLS ASSOC-LANGUAGE
characteristics?: string; // HLS CHARACTERISTICS
channels?: string; // HLS CHANNELS
audioCodec?: string;
groupId?: string; // HLS GROUP-ID
[key: string]: unknown;
}switchAudioTrack behaves as follows:
- All fields you pass must match a track. If any field doesn't match, the call is ignored without an error.
- Switching to the active track has no effect.
AUDIO_TRACK_CHANGEfires after the switch completes.- On hls.js, the player calls
hls.setAudioOption({ lang, name }), falling back tohls.audioTrack = idon older versions. On native iOS, it changes the matching track'senabledproperty.
Wait for AUDIO_TRACKS_UPDATED before you read the track list. An early empty list doesn't mean the source has one track.
playerSdkIns.on(VePlayer.Events.AUDIO_TRACKS_UPDATED, ({ audioTracks }) => {
const englishTrack = audioTracks.find(
(track) => track.lang?.toLowerCase() === 'en',
);
if (englishTrack) {
playerSdkIns.switchAudioTrack(englishTrack);
}
});
playerSdkIns.on(VePlayer.Events.AUDIO_TRACK_CHANGE, ({ id, audioTrack }) => {
console.log('Switched to track:', audioTrack.name, '(id:', id, ')');
});Common language codes
Audio track languages use BCP 47 codes. For the full registry, see RFC 5646.
Code | Language |
| Mandarin Chinese |
| Cantonese |
| Traditional Chinese |
| English |
| Japanese |
| Korean |
| French |
| German |
| Spanish |
| Arabic |
| Hindi |
| Thai |
| Vietnamese |
| Indonesian |
For more detail, see BytePlus Web Player SDK: multi-audio track.
Play H.265 videos
H.264 has the best compatibility, so you should use it. If you must use H.265, enable software decoding for devices that can't decode it in hardware. Software decoding can cause stuttering and lower performance.
const playerSdkIns = new VePlayer({
// Other player options
enableH265Degrade: true,
});

