All Products
Search
Document Center

ApsaraVideo VOD:Aliplayer API reference

Last Updated:Aug 27, 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 configure various properties, such as the authorization license, playback resources, player styles, and playback behavior.

Name

Type

Description

id

String

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

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. It overrides other methods such as VidAuth and VidSts. If you use VidAuth or VidSts, do not specify the `source` property. If `source` is specified, the player uses the URL from `source` for playback. Set only one playback method.

  • URL-based playback supports multiple definitions. Use the `source` property to specify the URLs for multiple definition streams. For more information, see Multi-definition playback. Example:

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

vid

String

The media ID from 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 available for VidAuth playback 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 helps prevent carrier hijacking and significantly improves playback stability and success rate.

playConfig

JSON

Custom setting field for Vid-based playback (VidAuth and VidSts). The value is passed through to the VOD API. For information about the supported custom fields and their parameters, see Custom media playback settings (PlayConfig). Example value:

{"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 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 500 px and automatically adjusts the height based on the video's aspect ratio.

Alternatively, you can specify `height: '500px', autoSize: 'width'`. The player maintains a height of 500 px and automatically adjusts the width based on the video's 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

Specifies whether the player automatically loads the video.

cover

String

The default thumbnail of the player. Specify 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. When playing a live stream, users are prevented from dragging the progress bar. The default value is false. Set this to true when you play a live stream.

autoplay

Boolean

Specifies whether the player plays the video automatically. The autoplay feature may not work 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 in some scenarios. For more information, see Advanced Features.

autoplayPolicy

Object

The adaptive muted autoplay policy. This property takes effect only when autoplay is set to true. Example configuration:

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 succeeds, the mutedAutoplay event is triggered.

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

rePlay

Boolean

Specifies whether 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 in some Android browsers.

skinRes

Url

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

skinLayout

Array | Boolean

The layout configuration of functional components. If you do not set this property, 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. Example configuration:

skinLayoutIgnore: [
  'bigPlayButton', // Hide the large play button
  'controlBar.fullScreenButton' // Hide the full screen button on the control bar (use dot notation to select sub-components)
]
Note

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

controlBarVisibility

String

The behavior of the control bar. Valid values:

  • click: The control bar appears when a user clicks the player area.

  • hover (default): The control bar appears when a user moves the pointer over the player area.

  • always: The control bar is always visible.

  • never: The entire control bar is hidden.

showBarTime

Number

The time in milliseconds before the control bar automatically hides.

enableSystemMenu

Boolean

Specifies whether to allow the system's right-click context menu to be displayed. 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 for Vid-based playback. 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 for Vid+PlayAuth playback. 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)

  • SD (High Definition)

  • HD (Ultra High Definition)

  • OD (Original Quality)

  • 2K (2K)

  • 4K (4K)

defaultDefinition

String

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

  • FD (Low Definition)

  • LD (Standard Definition)

  • SD (High Definition)

  • HD (Ultra High Definition)

  • OD (Original Quality)

  • 2K (2K)

  • 4K (4K)

autoPlayDelay

Number

The delayed playback time. Unit: seconds.

language

String

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: Enable.

  • false (default): Disable.

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): Enable.

  • false: Disable.

stashInitialSizeForFlv

Number

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

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

loadDataTimeout

Number

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

waitingTimeout

Number

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

diagnosisButtonVisible

Boolean

Specifies whether to display the diagnosis button. Valid values:

  • true (default): Display the button.

  • false: Do not display the button.

disableSeek

Boolean

Disables seeking on the progress bar. Valid values:

  • true: Disable.

  • false (default): Do not disable.

encryptType

Number

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

  • 0: Play non-encrypted videos.

  • 1: Play privately encrypted videos.

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

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

progressMarkers

Array

An array of content for progress bar markers. 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 mode, specifies whether to enable frame synchronization. Valid values:

  • true: Enable frame synchronization.

  • false (default): Disable 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, use the hlsOption.maxLiveSyncPlaybackRate property to set frame synchronization in HLS live mode.

chasingFirstParagraph

Number

The first stage of frame synchronization. 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, use the hlsOption.maxLiveSyncPlaybackRate property to set frame synchronization in HLS live mode.

chasingSecondParagraph

Number

The second stage of frame synchronization. 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, use the hlsOption.maxLiveSyncPlaybackRate property to set frame synchronization in HLS live mode.

chasingFirstSpeed

Number

The playback speed for the first stage of frame synchronization. The default is 1.1×.

Note

This parameter is supported only in web player SDK versions earlier than 2.21.0. For versions 2.21.0 and later, use the hlsOption.maxLiveSyncPlaybackRate property to set frame synchronization in HLS live mode.

chasingSecondSpeed

Number

The playback speed for the second stage of frame synchronization. The default is 1.2×.

Note

This parameter is supported only in web player SDK versions earlier than 2.21.0. For versions 2.21.0 and later, use the hlsOption.maxLiveSyncPlaybackRate property to set frame synchronization in HLS live mode.

hlsOption.maxLiveSyncPlaybackRate

Number

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

  • Example configuration:

    hlsOption: {
      maxLiveSyncPlaybackRate: 1.5, // Set the speed for frame synchronization
      liveSyncDurationCount: 3 // Set the number of delayed segments that triggers frame synchronization
    }
  • Example meaning: When the live stream latency exceeds the duration of 3 segments, the player plays at 1.5× speed to catch up to a latency of 3 segments. (To ensure the player has enough buffer for network fluctuations, be cautious when modifying the liveSyncDurationCount value. A value that is too small may cause stuttering.)

Note

This parameter is supported only in web player SDK versions 2.21.0 and later.

flvFrameChasing

Boolean

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

  • true: Enable frame synchronization.

  • false: Disable frame synchronization.

The default value is false.

keyShortCuts

Boolean

Specifies whether to enable keyboard shortcuts. Valid values:

  • true: Enable keyboard shortcuts.

  • false: Disable 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 plays the video.

keyFastForwardStep

Number

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

rtsFallback

Boolean

If the browser does not support RTS or RTS stream pulling fails, the player automatically attempts to fall back to FLV or HLS for playback. It prioritizes FLV due to 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: HLS, FLV. If you do not set this parameter, the player automatically selects a protocol. It prioritizes the lower-latency FLV protocol. If the browser does not support FLV, it falls back to HLS.

rtsFallbackSource

String

We recommend using 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 unique user identifier. Pass the `traceId` to the public instrumentation service to track reported logs. By default, the web player SDK has log reporting enabled. Passing a `traceId` helps you identify users. If you do not pass a `traceId`, 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 versions 2.10.0 and later.

textTracks

Array

Sets external WebVTT captions. 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: subtitles and captions.

  • label: The caption name to display.

  • srclang: The caption language.

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

  • default: Specifies whether to display the caption by default. Valid values: true and false. This field is supported only in web player SDK versions 2.15.7 and later.

Note
  • Supported in web player SDK versions 2.12.0 and later.

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

    • IE

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

    • Other browsers that hijack the video tag

  • For detailed information about caption properties, see the HTML specification.

  • For more advanced settings for captions, see External captions.

ratio

Number

Sets the player to scale at a fixed 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 some UI elements. For example, to change the display text for a resolution: HD is displayed as High Definition by default. You can change the display text for HD to 1080p as follows.

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

speedLevels

Array

Sets a custom array for the speed level list. `key` represents the speed value, and `text` represents the UI text. If not passed, the default list is used. Example parameter values:

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 custom logo images. 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 and 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 (Legacy), 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:

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

mute

Boolean

Sets whether to play the video on mute. You can configure this parameter for muted autoplay when the browser prohibits autoplay. For more information, see Advanced features.

clickPause

Boolean

Click the video area to pause or play.

disablePip

Boolean

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

Note
  • Supported in web player SDK versions 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. Playback and seeking are restricted to the time range between the start and end times.

Unit: seconds

watchEndTime

Number

Used with `watchStartTime` to enable range playback. Playback and seeking are restricted to the time range between the 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 an independent video. For example, for a 60-second video, if you set `start:10` and `end:30`, the displayed video duration is 20 seconds, and playback starts 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 an independent video. For example, for a 60-second video, if you set `start:10` and `end:30`, the displayed video duration is 20 seconds, and playback starts from the 10-second mark of the original video.

dbClickFullscreen

Boolean

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

longPressFastForward

Boolean

Long-press for fast forward (mobile only). Valid values:

  • true (default): Enable.

  • false: Disable.

dbClickSkip

Boolean

Double-click the left area to fast backward, double-click the right area to fast forward (mobile only). Valid values:

  • true (default): Enable.

  • false: Disable.

Methods

Methods must be called after the `ready` event occurs or within the `ready` callback of the player constructor. For 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

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.

Function definition

(time: number) => Player 

Parameters

Name

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 return value is in seconds.

Function definition

() => number

getDuration()

Retrieves the total duration of the video. The return value is in seconds. This method can be called after the video has loaded, for example, after the `play` event.

Function definition

() => number

getVolume()

Retrieves the current volume. The return value is a real number from 0 to 1. This method may not work on iOS or some Android devices.

Function definition

() => number | undefined

setVolume()

Sets the volume.

Function definition

(volume: number) => void

Parameters

Name

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

Type

Required

Description

quiet

boolean

No

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

unMute()

Unmutes the player.

Function definition

(quiet?: boolean) => Player

Parameters

Name

Type

Required

Description

quiet

boolean

No

Specifies whether to hide the text tip 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 real-time playback during speed changes.

Function definition

() => number

loadByUrl()

Switches the video source by URL. Currently, only switching between sources of the same format, such as MP4, HLS, or FLV, is supported. To switch between different formats, you must destroy the player instance and create a new one.

Function definition

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

Parameters

Name

Type

Required

Description

url

string

Yes

The URL of the video to switch to.

seconds

number

No

The start position after switching.

autoPlay

boolean

No

Specifies whether to autoplay after switching.

replayByVidAndPlayAuth()

Switches the VOD video. Only switching between videos of the same format is supported.

Function definition

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

Parameters

Name

Type

Required

Description

vid

string

Yes

The video ID.

playauth

string

Yes

The playback credential.

replayByVidAndAuthInfo()

Switches the ApsaraVideo Media Processing (MPS) video. Only switching between videos of the same format is supported.

Function definition

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

For more information about the parameters, see MPS playback.

replayByMediaAuth()

Switches the video from a general media service. Only switching between videos of the same format is supported.

Function definition

(mediaAuth: string) => void

Parameters

Name

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

Type

Required

Description

name

string

Yes

The name of the built-in component (e.g., `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

Type

Required

Description

width

string

Yes

Sets the player size. Valid values:

  • 400px

  • 60%

height

string

Yes

setSpeed()

Sets the playback speed. This method may not work on some mobile devices, such as on WeChat for Android. The playback speed UI is enabled by default.

Function definition

(speed: number) => void

Parameters

Name

Type

Required

Description

speed

number

Yes

Supports playback speeds from 0.5× to 2×.

Note

Disabling the speed control:

  • You cannot disable or customize the speed control 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 service for log tracking.

Function definition

(traceId: string) => void

Parameters

Name

Type

Required

Description

traceId

string

Yes

A unique identifier.

Note

Supported in web player SDK versions 2.10.0 and later.

setSanpshotProperties()

Sets the snapshot parameters.

Function definition

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

Parameters

Name

Type

Required

Description

width

number

Yes

The unit of height and width is pixel. The value for screenshot quality is a number ranging from 0 to 1. The default value is 1. For more information about video screenshots, see Video Screenshot.

height

number

Yes

rate

number

Yes

fullscreenService.requestFullScreen()

Requests the player to enter full screen mode.

Function definition

() => Player

fullscreenService.cancelFullScreen()

Requests the player to exit 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 return value is a string. Example values include the following:

  • init: Initialization.

  • ready: Ready.

  • loading: Loading.

  • play: Play.

  • pause: Pause.

  • playing: Playing.

  • waiting: Waiting for buffer.

  • error: Error.

  • ended: Ended.

Function definition

() => string

liveShiftSerivce.setLiveTimeRange()

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

Function definition

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

Parameters

Name

Type

Required

Description

start

string

Yes

start The start time of the live stream.

end

string

Yes

end 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

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 mode.

Function definition

(type: string) => void

Parameters

Name

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

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

Type

Required

Description

markers

Array<markers>

Yes

markers: A collection of marker data (required).

marker.time: The time for the marker (required).

marker.text: The text for the marker (required).

For more information, see the progressMarkers parameter.

setPreviewTime()

Sets the preview time.

Function definition

(time: number) => void

Parameters

Name

Type

Required

Description

time

number

Yes

Unit: seconds. For more information, see Preview.

getPreviewTime()

Retrieves the preview time.

Function definition

() => number

isPreview()

Checks whether the player is in preview mode.

Function definition

() => boolean

getCurrentPDT()

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

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

Type

Required

Description

textTracks

Array<object>

Yes

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 versions 2.12.0 and later.

setLogo()

Sets custom logo images.

Function definition

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

Parameters

Name

Type

Required

Description

logoList

Array<object>

Yes

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

Type

Required

Description

start

string

Yes

start start time.

end

string

Yes

end end time.

setNextWatchTime()

Sets the `watchStartTime` and `watchEndTime` for the next video. If you use `loadByUrl` or `replayByVidAndPlayAuth` to switch to a video with a different playback range, you can call `setNextWatchTime` beforehand to set the range for the upcoming video.

Function definition

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

Parameters

Name

Type

Required

Description

start

string

Yes

start start time.

end

string

Yes

end end time.

setStartEnd()

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

Function definition

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

Parameters

Name

Type

Required

Description

start

string

Yes

start start time.

end

string

Yes

end end time.

setNextStartEnd()

Sets the `start` and `end` for the next video. If you use `loadByUrl` or `replayByVidAndPlayAuth` to switch to a video with a different clipping range, you can call `setNextStartEnd` beforehand to set the range for the upcoming video.

Function definition

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

Parameters

Name

Type

Required

Description

start

string

Yes

start start time.

end

string

Yes

end end time.

takeSnapshot()

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

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

Function definition

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

Return value

Name

Type

Description

time

string

The time of the snapshot.

base64

string

The snapshot content in base64.

binary

string

The snapshot content as a binary string.

error

Error

Details of the snapshot error.

Events

Player events

Name

Description

ready

Triggered when the player's video initialization buttons have 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 player's methods can be called only after this event occurs.

play

Triggered when the video resumes playing from a paused state.

pause

Triggered when the video is paused.

canplay

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

playing

Triggered multiple times while the video is playing.

ended

Triggered when the current video finishes playing.

liveStreamStop

Triggered when a 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 an error occurs, the player automatically retries 5 times. No retry logic is needed at the upper layer.

onM3u8Retry

The retry event after an HLS live stream is interrupted. 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 screenshot completion event.

requestFullScreen

The full screen event.

cancelFullScreen

The cancel full screen event. This event is not triggered on iOS.

error

The error event.

startSeek

Triggered at the start of a seek operation. The parameter returns the time of the seek point.

completeSeek

Triggered at the completion of a seek operation. The parameter returns the time of the seek point.

resolutionChange

In a live stream, triggered when the stream ingest source switches resolution.

seiFrame

An SEI message is received for an HLS or FLV stream.

rtsFallback

Triggered when RTS falls back. The parameter reason is the reason for the fallback, and fallbackUrl is the URL being fallen back to.

settingSelected

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

Note

Because the open-source 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

This event is triggered when an RTS stream is successfully pulled. You can subscribe to this event to obtain the RTS TraceId. In the log output, the `traceId` field in the data.paramData parameter is the TraceId for the stream pulling, and the `source` field 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. If the callback parameter event.paramData is true, autoplay was successful. If it is false, autoplay failed, and user interaction is required for playback.

mutedAutoplay

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

videoUnavailable

Triggered when video playback results in a black screen because the video encoding format is not supported. For example, playing an H.265 video in a browser that does not support H.265 will result in a black screen with only audio, which triggers this event.

Subscribe to events

  • To subscribe to an event, use the `on` method of the player instance. For example:

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

    player.off('ready',handleReady);