This topic describes the properties, methods, and events that Aliplayer supports.
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
|
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: |
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:
|
width | String | The player width. Valid values:
|
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:
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 Note
|
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: Note The `skinLayoutIgnore` property has a higher priority than the `skinLayout` property. |
controlBarVisibility | String | The behavior of the control bar. Valid values:
|
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:
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:
|
qualitySort | String | Specifies the sorting order. This is supported only for Vid+PlayAuth playback. Valid values:
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:
|
defaultDefinition | String | The default video definition. This value is one of the definitions available for the `vid`. Valid values:
|
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:
|
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:
|
enableStashBufferForFlv | Boolean | When playing FLV streams in H5, specifies whether to enable the playback cache. This works only for live streaming. Valid values:
|
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:
|
disableSeek | Boolean | Disables seeking on the progress bar. Valid values:
|
encryptType | Number | Specifies whether to play Alibaba Cloud-encrypted (private encryption) videos. The default value is 0. Valid values:
Note
|
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:
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 |
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 |
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 |
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 |
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 | Number | In HLS live mode, sets the playback speed for frame synchronization. The default value is 1, which means frame synchronization is disabled.
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:
The default value is false. |
keyShortCuts | Boolean | Specifies whether to enable keyboard shortcuts. Valid values:
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: Field descriptions:
Note
|
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 |
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. |
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: |
logo | Array | Sets custom logo images. Example: Field descriptions:
|
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: |
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
|
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:
|
dbClickSkip | Boolean | Double-click the left area to fast backward, double-click the right area to fast forward (mobile only). Valid values:
|
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
() => Playerpause()
Pauses the video.
(showPlayButton?: boolean) => PlayerParameters
Name | Type | Required | Description |
showPlayButton | Boolean | No | Specifies whether to show the play button. |
replay()
Replays the video.
Function definition
() => Playerseek()
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
() => voidgetCurrentTime()
Retrieves the current playback time. The return value is in seconds.
Function definition
() => numbergetDuration()
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
() => numbergetVolume()
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 | undefinedsetVolume()
Sets the volume.
Function definition
(volume: number) => voidParameters
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) => PlayerParameters
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) => PlayerParameters
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
() => numberloadByUrl()
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) => voidParameters
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) => voidParameters
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) => voidFor 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) => voidParameters
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) => voidParameters
Name | Type | Required | Description |
width | string | Yes | Sets the player size. Valid values:
|
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) => voidParameters
Name | Type | Required | Description |
speed | number | Yes | Supports playback speeds from 0.5× to 2×. |
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) => voidParameters
Name | Type | Required | Description |
traceId | string | Yes | A unique identifier. |
Supported in web player SDK versions 2.10.0 and later.
setSanpshotProperties()
Sets the snapshot parameters.
Function definition
(width: number, height: number, rate: number) => voidParameters
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
() => PlayerfullscreenService.cancelFullScreen()
Requests the player to exit full screen mode. This call has no effect on iOS.
Function definition
() => PlayerfullscreenService.getIsFullScreen()
Retrieves the full screen status of the player.
Function definition
() => booleangetStatus()
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
() => stringliveShiftSerivce.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) => voidParameters
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) => voidParameters
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
() => numberFor more information, see Set the display mode.
setImage()
Sets the image mirroring mode.
Function definition
(type: string) => voidParameters
Name | Type | Required | Description |
type | string | Yes | Valid values:
Example: setImage('horizon'). For more information, see Set the display mode. |
setCover()
Sets the thumbnail.
Function definition
(coverUrl: string) => voidParameters
Name | Type | Required | Description |
coverUrl | string | Yes | The thumbnail URL. |
setProgressMarkers()
Sets progress bar markers.
Function definition
(markers: Array<{ time: number, text: string }>) => voidParameters
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) => voidParameters
Name | Type | Required | Description |
time | number | Yes | Unit: seconds. For more information, see Preview. |
getPreviewTime()
Retrieves the preview time.
Function definition
() => numberisPreview()
Checks whether the player is in preview mode.
Function definition
() => booleangetCurrentPDT()
For the HLS video format, this method retrieves the Program-Date-Time (PDT) in real time.
Function definition
() => number | undefinedsetTextTracks()
Sets a group of WebVTT captions.
Function definition
(textTracks: Array<{ kind: string, label: string, src: string, srclang: string }>) => voidParameters
Name | Type | Required | Description |
textTracks | Array<object> | Yes | Example: 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 }>) => voidParameters
Name | Type | Required | Description |
logoList | Array<object> | Yes | Example: 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) => voidParameters
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) => voidParameters
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) => voidParameters
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) => voidParameters
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 |
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 |
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 |
autoplay | Triggered when autoplay succeeds or fails. If the callback parameter |
mutedAutoplay | Triggered when muted autoplay succeeds, if |
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);