All Products
Search
Document Center

ApsaraVideo VOD:Aliplayer API reference

Last Updated:Dec 04, 2025

This topic describes the properties, methods, and events that Aliplayer supports.

Note

If you encounter any problems, see Web player FAQ or Troubleshoot playback exceptions.

Properties

When you initialize Aliplayer, you can set various properties. These include properties for the license, playback resources, player style, and playback behavior.

Name

Type

Description

id

String

The DOM element ID of the outer container of the player.

source

String

When you use URL-based playback, use the source property to specify the video playback URL.

Note
  • URL-based playback has the highest priority over other methods such as VidAuth and VidSts. This means that when you use methods like VidAuth or VidSts, you must not specify the source property. If you specify the source property, the player prioritizes the URL in the source property for playback. We recommend that you set only one playback method.

  • The URL-based playback method supports multiple definitions. Use the source property to specify the URLs of multiple definition streams. For more information, see Multi-definition playback. The following code provides an example:

    source: '{"HD":"address1","SD":"address2"}'

vid

String

The media ID in ApsaraVideo Media Processing.

playauth

String

The playback credential. To obtain a playback credential, see Obtain audio and video playback credentials.

customVodServer

String

A custom VOD proxy domain name. This property is applicable to the VidAuth playback method in versions 2.32.0 and later. You must deploy a dedicated request proxy service. If the default VOD domain name (*.aliyuncs.com) is inaccessible, the player automatically falls back to your proxy service. This can effectively mitigate carrier hijacking risks and significantly improve playback stability and success rate.

playConfig

JSON

A custom settings field for Vid-based playback (VidAuth and VidSts). The settings are passed through to the VOD API. For information about the supported custom fields and their descriptions, see Custom media playback settings (PlayConfig). The following code provides a value example:

{"PlayDomain":"vod.test_domain","PreviewTime":"20","MtsHlsUriToken":"yqCD7******oVjslp5Q"}

authTimeout

Number

The validity period of the video playback URL obtained through Vid-based playback (VidAuth and VidSts). Unit: seconds. Default value: 7200.

Make sure that this period is longer than the actual video duration to prevent the playback URL from expiring before playback is complete.

height

String

The player height. Valid values:

  • 100%

  • 100px

width

String

The player width. Valid values:

  • 100%

  • 100px

autoSize

Boolean | String

The player size automatically adapts to the video content. Valid values: 'height', 'width'.

For example, you can specify `width: '500px', autoSize: 'height'`. The player maintains a width of 500px and automatically adjusts the height based on the actual video aspect ratio.

Alternatively, you can specify `height: '500px', autoSize: 'width'`. The player maintains a height of 500px and automatically adjusts the width based on the actual video aspect ratio.

Note: `autoSize: true` is equivalent to `autoSize: 'height'`, which means the height is adaptive by default.

videoWidth

String

The video width. For more information, see Set the display mode.

videoHeight

String

The video height. For more information, see Set the display mode.

preload

Boolean

The player automatically loads the video.

cover

String

The default thumbnail of the player. Enter a valid image URL. This property takes effect only when `autoplay` is set to false.

isLive

Boolean

Specifies whether the content is a live stream. If it is, the player prevents users from dragging the progress bar. The default value is false. Set this to true when playing a live stream.

autoplay

Boolean

Specifies whether the player autoplays the video. The autoplay property is not effective on mobile devices. Valid values:

  • true: Enables autoplay.

  • false (default): Disables autoplay.

Note

Due to browser restrictions, the Web Player SDK may fail to autoplay videos in some scenarios. For more information, see Advanced features.

autoplayPolicy

Object

The adaptive muted autoplay policy for the player. This property takes effect only when autoplay is set to true. The following code provides a configuration example:

autoplayPolicy: {
  fallbackToMute: true, // Specifies whether to fall back to muted autoplay if autoplay with sound fails. Default: false.
  showUnmuteBtn: true, // Specifies whether to display a large unmute button in the center during muted autoplay. Default: true.
}
Note
  • When muted autoplay is successful, the mutedAutoplay event is triggered.

  • When autoplay is enabled (autoplay is set to true) and adaptive muted autoplay is also enabled (autoplayPolicy.fallbackToMute is set to true), the player first attempts to autoplay with sound. If this fails, it falls back to attempting muted autoplay. Note that muted autoplay is not guaranteed to be 100% successful.

rePlay

Boolean

The player automatically loops the playback.

useH5Prism

Boolean

Specifies whether to use the H5 player.

playsinline

Boolean

Specifies whether to play the video inline in H5. This may not work on some Android browsers.

skinRes

Url

The skin image. We recommend that you do not modify this field. To make changes, see Set the player skin.

skinLayout

Array | Boolean

The layout configuration for functional components. If you do not specify this field, the default layout is used. A value of `false` hides all functional components. For more information, see Configure the skinLayout property.

skinLayoutIgnore

Array

The UI components to hide. For component names, see VOD component parameters. The following code provides a configuration example:

skinLayoutIgnore: [
  'bigPlayButton', // Hides the large play button.
  'controlBar.fullScreenButton' // Hides the full screen button on the control bar (selects a sub-component using dot notation).
]
Note

The `skinLayoutIgnore` property has a higher priority than the `skinLayout` property.

controlBarVisibility

String

The implementation of the control panel. The valid values are:

  • click: Clicks the player area.

  • hover (default): Moves to the player area.

  • always: The control bar is always displayed.

  • never: Hides the entire control bar.

showBarTime

Number

The time in milliseconds before the control bar automatically hides.

enableSystemMenu

Boolean

Specifies whether to show the system's right-click menu. The default value is false.

format

String

Specifies the format of the playback URL. Valid values:

  • mp4

  • hls or m3u8

  • flv

  • mp3

The default value is empty.

mediaType

String

Specifies whether to return audio or video. This is supported only when you use the `vid` playback method. The default value is video. Valid values:

  • video: Video.

  • audio: For video formats that contain only audio, such as an MP4 audio file.

qualitySort

String

Specifies the sorting order. This is supported only when you use the Vid + PlayAuth playback method. Valid values:

  • desc: Sorts in descending order (from largest to smallest).

  • asc: Sorts in ascending order (from smallest to largest).

Default value: asc.

definition

String

The video definitions to display, separated by commas (,). For example, 'FD,LD'. This value is a subset of the definitions available for the `vid`. Valid values:

  • FD (Low Definition)

  • LD (Standard Definition)

  • HD (high definition)

  • HD (Ultra High Definition)

  • OD (Original Quality)

  • 2K (2K)

  • 4K (4K)

defaultDefinition

String

The default video definition. This value must be one of the definitions available for the `vid`. Valid values:

  • FD (Low Definition)

  • LD (Standard Definition)

  • HD (high definition)

  • HD (Ultra High Definition)

  • OD (Original Quality)

  • 2K (2K)

  • 4K (4K)

autoPlayDelay

Number

The delay before playback starts. Unit: seconds.

language

String

The language for internationalization. The default value is zh-cn. If not set, the browser's language is used. Valid values:

  • zh-cn: Chinese.

  • en-us: English.

languageTexts

JSON

A JSON object for custom internationalization text. The key must correspond to the value of the `language` property. Example: {jp:{Play:"Play"}}. For the JSON structure, see JSON structure.

snapshotWatermark

Object

Sets a watermark for screenshots in H5.

useHlsPluginForSafari

Boolean

Specifies whether to enable the HLS plugin for playback in Safari browsers, except for Safari 11. Valid values:

  • true: Enables the plugin.

  • false (default): Disables the plugin.

enableStashBufferForFlv

Boolean

When playing FLV streams in H5, specifies whether to enable the playback cache. This works only for live streaming. Valid values:

  • true (default): Enables the cache.

  • false: Disables the cache.

stashInitialSizeForFlv

Number

When playing FLV streams in H5, this is the initial cache size. This works only for live streaming. The default is 32 KB.

A smaller value can speed up the initial playback, but if the value is too small, it may cause stuttering after a short period of playback.

loadDataTimeout

Number

The buffering duration in seconds after which the player prompts the user to switch to a lower definition. The default is 20 seconds.

waitingTimeout

Number

The maximum buffering timeout period. If this period is exceeded, an error is prompted. Unit: seconds. The default is 60 seconds.

diagnosisButtonVisible

Boolean

Specifies whether to display the diagnosis button. Valid values:

  • true (default): Displays the button.

  • false: Does not display the button.

disableSeek

Boolean

Disables seeking on the progress bar. Valid values:

  • true: Disables seeking.

  • false (default): Does not disable.

encryptType

Number

Specifies whether to play videos encrypted with Alibaba Cloud private encryption. The default value is 0. Valid values:

  • 0: Plays unencrypted videos.

  • 1: Plays privately encrypted videos.

Note
  • Private encryption uses the VID + Playauth method for playback.

  • For standard encryption on the web, use the URL playback method. See Encrypted playback.

progressMarkers

Array

An array of content for marking the progress bar. For more information, see Progress bar markers.

vodRetry

Number

The number of retry attempts for failed VOD playback. The default is 3.

liveRetry

Number

The number of retry attempts for failed live playback. The default is 5.

hlsFrameChasing

Boolean

In HLS live streaming mode, specifies whether to enable frame synchronization. Valid values:

  • true: Enables frame synchronization.

  • false (default): Disables frame synchronization.

Note

This parameter is supported only in Web Player SDK versions earlier than 2.21.0. For versions 2.21.0 and later, to set frame synchronization in HLS live streaming mode, see the hlsOption.maxLiveSyncPlaybackRate property.

chasingFirstParagraph

Number

The duration of the first frame synchronization segment. Unit: seconds. The default is 20 seconds.

Note

This parameter is supported only in Web Player SDK versions earlier than 2.21.0. For versions 2.21.0 and later, to set frame synchronization in HLS live streaming mode, see the hlsOption.maxLiveSyncPlaybackRate property.

chasingSecondParagraph

Number

The duration of the second frame synchronization segment. Unit: seconds. The default is 40 seconds.

Note

This parameter is supported only in Web Player SDK versions earlier than 2.21.0. For versions 2.21.0 and later, to set frame synchronization in HLS live streaming mode, see the hlsOption.maxLiveSyncPlaybackRate property.

chasingFirstSpeed

Number

The playback speed for the first frame synchronization segment. The default is 1.1x.

Note

This parameter is supported only in Web Player SDK versions earlier than 2.21.0. For versions 2.21.0 and later, to set frame synchronization in HLS live streaming mode, see the hlsOption.maxLiveSyncPlaybackRate property.

chasingSecondSpeed

Number

The playback speed for the second frame synchronization segment. The default is 1.2x.

Note

This parameter is supported only in Web Player SDK versions earlier than 2.21.0. For versions 2.21.0 and later, to set frame synchronization in HLS live streaming mode, see the hlsOption.maxLiveSyncPlaybackRate property.

hlsOption.maxLiveSyncPlaybackRate

Number

In HLS live streaming mode, sets the playback speed for live frame synchronization. The default is 1, which means frame synchronization is disabled.

  • Configuration example:

    hlsOption: {
      maxLiveSyncPlaybackRate: 1.5, // Sets the playback speed for frame synchronization.
      liveSyncDurationCount: 3 // Sets the number of delayed segments that triggers frame synchronization.
    }
  • Example meaning: When the live streaming latency is greater than the duration of 3 segments, the player plays at 1.5x speed to catch up to a latency of 3 segments. Because the player needs a certain buffer to handle network fluctuations, modify the value of liveSyncDurationCount with caution. A value that is too small may cause stuttering.

Note

This parameter is supported only in Web Player SDK 2.21.0 and later.

flvFrameChasing

Boolean

In FLV live streaming mode, specifies whether to enable frame synchronization. Valid values:

  • true: Enables frame synchronization.

  • false: Disables frame synchronization.

The default value is false.

keyShortCuts

Boolean

Specifies whether to enable keyboard shortcuts. Valid values:

  • true: Enables keyboard shortcuts.

  • false: Disables keyboard shortcuts.

The default value is false.

Note

The left and right arrow keys control fast backward and fast forward. The up and down arrow keys control the volume. The space bar pauses and resumes playback.

keyFastForwardStep

Number

The time increment for fast forward and fast backward. Unit: seconds. The default is 10 seconds.

rtsFallback

Boolean

When the browser does not support RTS or RTS stream pulling fails, the player automatically tries to fall back to FLV or HLS for playback. It prioritizes FLV for lower latency. If the browser does not support FLV, it falls back to HLS.

This feature is enabled by default. To disable it, you can pass `false`.

rtsFallbackType

String

Specifies the protocol to fall back to from RTS. Valid values are HLS or FLV. If you do not pass this parameter, the player automatically selects a protocol. It prioritizes FLV for lower latency. If the browser does not support FLV, it falls back to HLS.

rtsFallbackSource

String

We recommend that you use the player's default fallback policy. However, if you want to specify a fixed stream pulling URL for fallback, use this parameter.

traceId

String

The `traceId` is your own unique user identifier. Pass the `traceId` to the public instrumentation for tracking reported logs. By default, the Web Player SDK has log reporting enabled. Passing a `traceId` helps you identify users. If you do not pass it, the Web Player SDK generates a UUID (a unique identifier generated by the player SDK) and stores it in the browser cache.

Note

Supported in Web Player SDK 2.10.0 and later.

textTracks

Array

Sets WebVTT external captions. The following code provides an example:

textTracks: [
  { kind: 'subtitles', label: 'Chinese', src: 'caption_url', srclang: 'zh-CN', default: true },
	{ kind: 'subtitles', label: 'English (US)', src: 'caption_url', srclang: 'en-US' }
],

Field descriptions:

  • kind: The VTT type. Valid values include `subtitles` and `captions`.

  • label: The caption name to be displayed.

  • srclang: The caption language.

  • src: The caption URL. Allow cross-domain access.

  • default: Specifies whether to display the caption by default. Valid values are `true` and `false`. This field is supported only in Web Player SDK 2.15.7 and later.

Note
  • Supported in Web Player SDK 2.12.0 and later.

  • WebVTT external captions are not supported in the following browsers:

    • IE

    • QQ Browser for Android, system browsers for OPPO/OnePlus

    • Other browsers that hijack the video tag

  • For detailed descriptions of caption properties, see the HTML specification.

  • For more advanced caption settings, see External captions.

ratio

Number

Sets the player to scale at a fixed aspect ratio. For example, if a video has a 16:9 aspect ratio, you can set the player parameters to width: "100%", ratio: 16/9. This keeps the player's aspect ratio consistent with the video content and allows it to scale proportionally as the page is resized.

extLanguageTexts

Object

The Player SDK has a built-in set of UI text in Chinese and English. You can use this property to customize the display text for parts of the UI. For example, to change the display text for the HD resolution, which defaults to 高清 (High Definition), you can change it to 1080p as follows:

extLanguageTexts: {
    'zh-cn': {
      'HD': "1080p"
    }
}

speedLevels

Array

Sets a custom playback speed list array. `key` represents the speed value, and `text` represents the UI text. If not passed, the default list is used. The following code provides a parameter value example:

speedLevels: [
  {"key": 0.25, "text": "0.25"},
  {"key": 0.5, "text": "0.5"},
  {"key": 1, "text": "Normal"},
  {"key": 1.25, "text": "1.25"},
  {"key": 1.5, "text": "1.5"},
  {"key": 2,"text": "2"}
]

logo

Array

Sets a custom logo image. The following code provides an example:

    logo: [{
      width: 30,
      position: 'bottom-right',
      origin: 'content',
      src: 'a.png'
    },
    {
      width: 20,
      position: 'bottom-right',
      offsetY: -20,
      origin: 'content',
      src: 'b.png'
    }]

Field descriptions:

  • src: The logo image URL.

  • origin: The reference object for positioning. Valid values:

    • box: The player

    • content: The video content

  • width/height: The width/height of the logo as a percentage (calculated based on `origin`). If you specify only one dimension, the other is scaled proportionally based on the image's aspect ratio.

  • position: The relative position of the logo, positioned relative to `origin`. Valid values:

    • top-left: Top left

    • top-right: Top right

    • bottom-left: Bottom left

    • bottom-right: Bottom right

  • offsetX/offsetY: The offset from the `position`, as a percentage (calculated based on `origin`).

license

Object

To use value-added services such as Playback Quality Monitoring (Old Version), Single-point tracing, and playing H.265/H.266 encoded video streams, first fill out the Web Player SDK Value-added Service Application Form to apply for a license. Then, integrate the license as follows:

// The domain is the domain name you provided when applying for the license.
// The key is the license key.
license: {
    domain: "example.com",
    key: "example-key"
  }

mute

Boolean

Sets whether to play the video on mute. When browsers prohibit autoplay, you can configure this parameter for muted autoplay. For more information, see Advanced features.

clickPause

Boolean

Click the video screen to pause or play.

  • true: Enabled.

  • false: Disabled.

The default value is `true` on PCs and `false` on mobile devices. Do not use this property with the `dbClickSkip` property to avoid interaction conflicts.

disablePip

Boolean

Hides the browser's native Picture-in-Picture (PiP) button.

Note
  • Supported in Web Player SDK 2.20.0 and later.

  • Supported only in Firefox 116 and later.

env

String

The player's instrumentation data is uploaded to the China data center by default. If you have data compliance requirements for regions outside China, pass the parameter `env: 'SEA'`. The data will be uploaded to the Singapore data center.

watchStartTime

Number

Used alone, it represents the start time of playback.

Used with `watchEndTime`, it enables range playback, allowing playback and seeking only within the specified start and end times.

Unit: seconds

watchEndTime

Number

Used with `watchStartTime` to enable range playback, allowing playback and seeking only within the specified start and end times.

If this parameter's value is less than `watchStartTime`, `watchStartTime` becomes invalid.

Unit: seconds

start

Number

Used with `end` to clip a part of the video and treat it as a separate video. For example, for a 60-second video, setting `start:10` and `end:30` results in a video with a displayed duration of 20 seconds, starting playback from the 10-second mark of the original video.

end

Number

Used with `start` to clip a part of the video and treat it as a separate video. For example, for a 60-second video, setting `start:10` and `end:30` results in a video with a displayed duration of 20 seconds, starting playback from the 10-second mark of the original video.

dbClickFullscreen

Boolean

Specifies whether to enable double-click to enter full screen. This is enabled by default on PCs.

longPressFastForward

Boolean

The long-press for fast-forward feature (mobile only). Valid values:

  • true (default): Enabled.

  • false: Disabled.

dbClickSkip

Boolean

The double-click to skip feature (mobile only), where double-clicking the left area fast-backwards and the right area fast-forwards. Valid values:

  • true (default): Enabled.

  • false: Disabled.

Do not use this property with the `clickPause` property to avoid interaction conflicts.

enableMockFullscreen

Boolean

Web page full screen feature. The player calls the browser's full screen API by default. On iOS browsers and some Android browsers, full screen mode is taken over by the system player, which can cause issues like the UI disappearing. To prevent this, you can enable this parameter to implement a pseudo-full screen using CSS. The default value is false.

Methods

Methods must be called after the `ready` event occurs. You can call methods within the `ready` callback function of the player constructor. The following code provides an example:

// Method 1:
var player = new Aliplayer({}, function (player) {
  player.play();
});

// Method 2:
var player = new Aliplayer({});
function handleReady(player) {
  player.play();
};
player.on('ready', handleReady);

The following methods can be called on an Aliplayer instance:

play()

Plays the video.

Function definition

() => Player

pause()

Pauses the video.

(showPlayButton?: boolean) => Player

Parameters

Name

Parameter type

Required

Description

showPlayButton

Boolean

No

Specifies whether to show the play button.

replay()

Replays the video.

Function definition

() => Player

seek()

Seeks to a specific time for playback.

Function definition

(time: number) => Player 

Parameters

Name

Parameter type

Required

Description

time

number

Yes

The time to seek to. Unit: seconds.

dispose()

Destroys the player.

Function definition

() => void

getCurrentTime()

Retrieves the current playback time. The returned value is in seconds.

Function definition

() => number

getDuration()

Retrieves the total duration of the video in seconds. This method can be called after the video is loaded, such as after the `play` event occurs.

Function definition

() => number

getVolume()

Retrieves the current volume. The returned value is a real number from 0 to 1. This feature may not be supported on iOS or some Android devices.

Function definition

() => number | undefined

setVolume()

Sets the volume.

Function definition

(volume: number) => void

Parameters

Name

Parameter type

Required

Description

volume

number

Yes

vol is a real number from 0 To 1. This may not work on iOS and some Android devices.

mute()

Mutes the player.

Function definition

(quiet?: boolean) => Player

Parameters

Name

Parameter type

Required

Description

quiet

boolean

No

Specifies whether to hide the text prompt in the lower-left corner when muting.

unMute()

Unmutes the player.

Function definition

(quiet?: boolean) => Player

Parameters

Name

Parameter type

Required

Description

quiet

boolean

No

Specifies whether to hide the text prompt in the lower-left corner when unmuting.

getPlayTime()

Retrieves the user's actual playback duration in seconds. This duration excludes time when the video is paused and accounts for the physical time elapsed during speed changes.

Function definition

() => number

loadByUrl()

Loads a new video by URL. This method supports switching between videos of the same format, such as MP4, HLS, or FLV. To switch between videos of different formats, you must destroy the current player instance and create a new one.

Function definition

(url: string, seconds?: number, autoPlay?: boolean) => void

Parameters

Name

Parameter type

Required

Description

url

string

Yes

The URL of the video to switch to.

seconds

number

No

The starting position after switching.

autoPlay

boolean

No

Specifies whether to autoplay after switching.

replayByVidAndPlayAuth()

VOD supports switching between videos of the same format only.

Function definition

(vid: string, playauth: string) => void

Parameters

Name

Parameter type

Required

Description

vid

string

Yes

The video ID.

playauth

string

Yes

The playback credential.

replayByVidAndAuthInfo()

Replays an ApsaraVideo Media Processing (MPS) video. This method only supports switching between videos of the same format.

Function definition

(vid: string, accId: string, accSecret: string, stsToken: string, authInfo: string, domainRegion: string) => void

For more information, see MPS playback.

replayByMediaAuth()

Replays a video from a general media service. This method only supports switching between videos of the same format.

Function definition

(mediaAuth: string) => void

Parameters

Name

Parameter type

Required

Description

mediaAuth

string

Yes

The playback credential.

getBuildInComponent()

Retrieves a built-in UI component, such as the full-screen button or the progress bar.

Function definition

(name: string) => BuildInComponent;

Parameters

Name

Parameter type

Required

Description

name

string

Yes

For the names of built-in components (such as `fullScreenButton`), see Configure the skinLayout property. Each component supports `hide()` and `show()` methods to control its visibility.

setPlayerSize()

Sets the player size.

Function definition

(width: string, height: string) => void

Parameters

Name

Parameter type

Required

Description

width

string

Yes

Sets the player size. Valid values:

  • 400px

  • 60%

height

string

Yes

setSpeed()

Sets the playback speed. This feature may not be supported on some mobile devices, such as on WeChat for Android. By default, the playback speed UI is enabled.

Function definition

(speed: number) => void

Parameters

Name

Parameter type

Required

Description

speed

number

Yes

Supports playback speeds from 0.5x to 2x.

Note

How to disable playback speed control:

  • You cannot disable or customize the speed options individually. You can only disable the entire settings menu.

  • A workaround to disable the speed control is to override the style:

    .prism-setting-speed {
       display: none !important;
     }

setTraceId()

Passes a value to the public instrumentation for log tracking.

Function definition

(traceId: string) => void

Parameters

Name

Parameter type

Required

Description

traceId

string

Yes

A unique identifier.

Note

This feature is supported in Web Player SDK 2.10.0 and later.

setSanpshotProperties()

Sets snapshot parameters.

Function definition

(width: number, height: number, rate: number) => void

Parameters

Name

Parameter type

Required

Description

width

number

Yes

The height and width are in px. The screenshot quality is a number between 0 and 1, with a default of 1. For detailed information about video screenshots, see Video screenshots.

height

number

Yes

rate

number

Yes

fullscreenService.requestFullScreen()

Enters full-screen mode.

Function definition

() => Player

fullscreenService.cancelFullScreen()

Exits full-screen mode. This call has no effect on iOS.

Function definition

() => Player

fullscreenService.getIsFullScreen()

Retrieves the full-screen status of the player.

Function definition

() => boolean

getStatus()

Retrieves the player status. The returned string value can be one of the following:

  • init: The player is initializing.

  • ready: The player is ready.

  • loading: Content is being loaded.

  • play: Starts playback.

  • pause: The video is paused.

  • playing: The video is playing.

  • waiting: The player is waiting for the buffer.

  • error: An error occurred.

  • Ended: The process is complete.

Function definition

() => string

liveShiftSerivce.setLiveTimeRange()

Sets the start and end times of a live stream. This method is used when the time shifting feature is enabled.

Function definition

(start: string, end: string) => void

Parameters

Name

Parameter type

Required

Description

start

string

Yes

start is the start time of the live stream.

end

string

Yes

end is the end time of the live stream.

Example

player.liveShiftSerivce.setLiveTimeRange('2025/03/21 12:43:00', '2025/03/21 23:31:00')

setRotate()

Sets the rotation angle of the player.

Function definition

(rotate: number) => void

Parameters

Name

Parameter type

Required

Description

rotate

number

Yes

A positive number indicates clockwise rotation, and a negative number indicates counter-clockwise rotation. Example: `setRotate(90)`. For more information, see Set the display mode.

getRotate()

Retrieves the rotation angle of the player.

Function definition

() => number

For more information, see Set the display mode.

setImage()

Sets the image mirroring.

Function definition

(type: string) => void

Parameters

Name

Parameter type

Required

Description

type

string

Yes

Valid values:

  • horizon: Horizontal.

  • vertical: Vertical.

Example: `setImage('horizon')`. For more information, see Set the display mode.

setCover()

Sets the thumbnail.

Function definition

(coverUrl: string) => void

Parameters

Name

Parameter type

Required

Description

coverUrl

string

Yes

The thumbnail URL.

setProgressMarkers()

Sets progress bar markers.

Function definition

(markers: Array<{ time: number, text: string }>) => void

Parameters

Name

Parameter type

Required

Description

markers

Array<markers>

Yes

markers: A collection of marker data. Required.

marker.time: The time of the marker. Required.

marker.text: The text for the marker. Required.

For more information, see the `progressMarkers` parameter.

setPreviewTime()

Sets the preview duration.

Function definition

(time: number) => void

Parameters

Name

Parameter type

Required

Description

time

number

Yes

Unit: seconds. For more information, see Preview.

getPreviewTime()

Retrieves the preview duration.

Function definition

() => number

isPreview()

Checks whether the current playback is a preview.

Function definition

() => boolean

getCurrentPDT()

For videos in HLS format, this method retrieves the real-time Program-Date-Time (PDT).

Function definition

() => number | undefined

setTextTracks()

Sets a group of WebVTT captions.

Function definition

(textTracks: Array<{ kind: string, label: string, src: string, srclang: string }>) => void

Parameters

Name

Parameter type

Required

Description

textTracks

Array<object>

Yes

The following code provides an example:

player.setTextTracks([ { kind: 'subtitles', label: 'Chinese', src: 'caption_url', srclang: 'zh-CN' },{ kind: 'subtitles', label: 'English (US)', src: 'caption_url', srclang: 'en-US' }])
Note

Supported in Web Player SDK 2.12.0 and later.

setLogo()

Sets a custom logo image.

Function definition

(logoList: Array<{ width: number, position: string, origin: string, src: string }>) => void

Parameters

Name

Parameter type

Required

Description

logoList

Array<object>

Yes

The following code provides an example:

player.setLogo([{
      width: 30,
      position: 'bottom-right',
      origin: 'content',
      src: 'a.jpg'
    },
    {
      width: 20,
      position: 'bottom-right',
      offsetY: -20,
      origin: 'content',
      src: 'b.jpg'
    }])

For detailed descriptions of each field, see the `logo` property.

setWatchTime()

Dynamically updates the `watchStartTime` and `watchEndTime` for the current video.

Function definition

(start: number, end: number) => void

Parameters

Name

Parameter type

Required

Description

start

string

Yes

start is the start time.

end

string

Yes

end is the end time.

setNextWatchTime()

Sets the `watchStartTime` and `watchEndTime` for the next video. If you plan to switch videos using `loadByUrl` or `replayByVidAndPlayAuth`, you can call this method to set the playback range for the next video.

Function definition

(start: number, end: number) => void

Parameters

Name

Parameter type

Required

Description

start

string

Yes

start is the start time.

end

string

Yes

end is the end time.

setStartEnd()

Dynamically updates the `start` and `end` times for the current video.

Function definition

(start: number, end: number) => void

Parameters

Name

Parameter type

Required

Description

start

string

Yes

start is the start time.

end

string

Yes

end is the end time.

setNextStartEnd()

Sets the `start` and `end` times for the next video. If you plan to switch videos using `loadByUrl` or `replayByVidAndPlayAuth`, you can call this method to set the clipping range for the next video.

Function definition

(start: number, end: number) => void

Parameters

Name

Parameter type

Required

Description

start

string

Yes

start is the start time.

end

string

Yes

end is the end time.

takeSnapshot()

Takes a snapshot. The returned base64 string can be directly loaded by `img.src`. You can use `setSnapshotProperties` to set the snapshot quality and `snapshotWatermark` to set a watermark.

Note: The snapshot feature may not be available on some mobile browsers, such as UC Browser or QQ Browser, where the video element is hijacked.

Function definition

() => { time: number, base64: string, binary: string, error: Error | null }

Return value

Name

Parameter type

Description

time

string

The time of the snapshot.

base64

string

The base64 content of the snapshot.

binary

string

The snapshot content as a binary string.

error

Error

Details of the snapshot exception.

showControlBar()

Shows the control bar.

Function definition

() => void

hideControlBar()

Hides the control bar.

Function definition

() => void

Events

Player events

Name

Description

ready

The player's video initialization button has finished rendering. Initial UI settings for the player must be triggered after this event to prevent them from being overwritten by the initialization.

Note

The methods provided by the player can only be called after this event has occurred.

play

Triggered when the video resumes playing from a paused state.

pause

Triggered when the video is paused.

canplay

Occurs when the audio and video can start playing. It can be triggered multiple times. This is for the H5 player only.

playing

Triggered multiple times during playback.

ended

Triggered when the current video finishes playing.

liveStreamStop

Triggered when the live stream is interrupted. For HLS live streams, this is triggered after 5 unsuccessful retry attempts. It indicates to the upper layer that the stream is interrupted or the video needs to be reloaded.

Note

If an HLS live stream is interrupted or encounters an error, the player automatically retries 5 times. No retry logic needs to be added at the upper layer.

onM3u8Retry

The retry event after an HLS live stream is interrupted. It is triggered only once per interruption.

hideBar

The event for the control bar automatically hiding.

showBar

The event for the control bar automatically showing.

waiting

The data buffering event.

timeupdate

Triggered when the playback position changes. You can get the current playback time using the `getCurrentTime` method.

snapshoted

The snapshot completion event.

requestFullScreen

The full screen event.

cancelFullScreen

The exit full screen event. Not triggered on iOS.

error

The error event.

startSeek

Starts seeking. The parameter returns the time of the seek point.

completeSeek

Completes seeking. The parameter returns the time of the seek point.

resolutionChange

In a live stream, the ingest endpoint has switched the resolution.

seiFrame

An SEI message is received for HLS or FLV.

rtsFallback

Triggered when RTS falls back. The reason parameter indicates the cause of the fallback, and the fallbackUrl parameter is the URL it falls back to.

settingSelected

Triggered when an item in a settings list (such as playback speed, definition, or captions) is selected.

Note

Because the open-source playback speed plugin is not synchronized with the player settings, using it requires custom code and recompilation. You can define an event listener. To use the player's settingSelected event, you must remove this plugin.

/**
 * A settings list item is selected, for example, switching speed to 1.25x:
 * {name: 'Speed', type: 'speed', text: '1.25X', key: 1.25}
 */

rtsTraceId

Triggered when RTS stream pulling is successful. By subscribing to this event, you can get the RTS TraceId. In the log printing, the `traceId` field in the data.paramData parameter is the TraceId of the stream pulling, and `source` is the playback URL of the current RTS stream.

player.on('rtsTraceId', function(data) {
  console.log('[EVENT]rtsTraceId', data.paramData);
})

autoplay

Triggered when autoplay succeeds or fails. The callback parameter event.paramData is true if autoplay is successful. It is false if autoplay fails, in which case user interaction is required to start playback.

mutedAutoplay

Triggered when muted autoplay is successful, if autoplayPolicy.fallbackToMute is set to true.

videoUnavailable

Triggered when the video playback results in a black screen because the video encoding format is not supported. For example, when playing an H.265 video in a browser that does not support H.265, the video screen is black, but the audio plays. This event is triggered in such cases.

Subscribe to events

  • You can subscribe to events using the `on` method of the player instance. The following code provides an example:

    function handleReady() {};
    player.on('ready', handleReady);
    // Some events are triggered frequently. You can use player.one to listen only once.
    player.one('canplay', () => {});
  • You can unsubscribe from events using the `off` method of the player instance. The following code provides an example:

    player.off('ready',handleReady);