ZWPlayer Method Description
1. Playback Control
1.1 play
play(url, isLive, useOldFlv);
Description: Start playback. Calling this method will initiate a new playback session.
| Parameter | Type | Optional | Description |
|---|---|---|---|
| url | string/object | Yes | Media stream URL address / Local file object, refer to url parameter description |
| isLive | boolean | Yes | Specify whether the media stream is a live stream |
| useOldFlv | boolean | Yes | Whether to use the old Flv playback interface |
Return Value: None
Detailed Description:
- If the player is currently playing, calling this method will reopen the media and start playback from the beginning
- If the player is playing a live stream, calling this method will close the current playback and establish a new connection
- All parameters can be omitted; if called without any parameters,
zwplayerwill start playback using the internally stored original parameters - If the
urlparameter was not passed during the constructor call and theplaymethod with aurlparameter has never been called, theplaycall will fail
1.2 pause
pause();
Description: Pause the current playback.
Parameters: None
Return Value: None
Detailed Description: The pause operation does not clear any internal player data.
1.3 stop
stop();
Description: Stop ongoing playback.
Parameters: None
Return Value: None
Detailed Description:
- Stopping playback differs from pausing; stopping playback will clear all internal player data and reset the player to its initial state
- The player object can still call
playafterwards to start a new playback session
1.4 resume
resume();
Description: Resume playback.
Parameters: None
Return Value: None
Detailed Description:
- If the player is paused, playback continues from the current position
- If the player is stopped, a new playback session is initiated
1.5 setplaystate
setplaystate(bPlaying);
Description: Set the playback state.
| Parameter | Type | Optional | Description |
|---|---|---|---|
| bPlaying | boolean | No | true: Set to playing, false: Set to paused |
Return Value: None
Playback Progress
2.1 getDuration
getDuration();
Description: Get the duration of the current media in the player.
Parameters: None
Return Value:
- Type: number (float)
- Description: Duration, in seconds
- Special Cases:
- Returns
undefinedif the player has no media loaded - Returns
Infinityif the duration of the media cannot be obtained
- Returns
2.2 getCurrentTime
getCurrentTime();
Description: Get the current playback position of the media in the player.
Parameters: None
Return Value:
- Type: number (float)
- Description: Playback position, in seconds
2.3 seekTime
seekTime(time);
Description: Seek to a specific playback time.
| Parameter | Type | Optional | Description |
|---|---|---|---|
| time | number | No | The time to seek to, in seconds (float) |
Return Value: None
Restriction: Valid only for VOD (on-demand) programs
3. Volume, Fullscreen & Screenshot
3.1 setMuted
setMuted(muted);
Description: Set the mute state. Pass true to mute, false to unmute and restore the previous volume.
| Parameter | Type | Optional | Description |
|---|---|---|---|
| muted | boolean | No | true: mute; false: unmute |
Return Value: None
Detailed Description:
- When unmuting, the volume recorded before muting is automatically restored
- When unmuting, if the browser’s AudioContext is suspended (due to autoplay policy), it is resumed to ensure audible playback
- The mute button state in the control bar is updated accordingly
- Equivalent to the user clicking the player’s mute button
3.2 setVolume
setVolume(volume);
Description: Set the playback volume.
| Parameter | Type | Optional | Description |
|---|---|---|---|
| volume | number | No | Volume value, range 0~1 (0 = mute, 1 = max volume) |
Return Value: None
Detailed Description:
- The volume applies to both the original audio track and external dubbed audio tracks
- If volume boost is enabled, this value serves as the base volume
3.3 setFullscreen
setFullscreen(isFullscreen);
Description: Enter or exit browser fullscreen.
| Parameter | Type | Optional | Description |
|---|---|---|---|
| isFullscreen | boolean | No | true: enter fullscreen; false: exit fullscreen |
Return Value: None
Detailed Description:
- Uses the browser’s native Fullscreen API
- When
iosWebFullscreenis configured on an iPhone, it automatically falls back to web fullscreen (setFullscreenWin) to avoid the native iOS player dropping watermarks, subtitles, and danmaku - Can be called directly without a button argument for programmatic control
- Some mobile browsers require fullscreen toggles to be triggered by a user gesture (click); programmatic calls may be blocked
3.4 doSnapshot
doSnapshot();
Description: Capture the current video frame and download it as an image.
Parameters: None
Return Value: None
Detailed Description:
- Generates a snapshot from the current frame, in JPG format (quality 0.99)
- Automatically triggers a download; filename format is
SNAP-<timestamp>.jpg(timestamp precise to the millisecond) - Also attempts to copy the snapshot to the system clipboard
- Cross-origin video sources restricted by CORS cannot be captured (browser security policy)
- When there is no video frame (e.g. audio-only mode or playback not yet started), no snapshot is taken
4. Danmaku (Bullet Comments) Functionality
4.1 setEnableDanmu
setEnableDanmu(bEnable);
Description: Enable or disable the Danmaku feature.
| Parameter | Type | Optional | Description |
|---|---|---|---|
| bEnable | boolean | No | true: Enable Danmaku, false: Disable Danmaku |
Return Value: None
4.2 appendDanmu
appendDanmu(danmuObj, setting);
Description: Add a Danmaku comment.
| Parameter | Type | Optional | Description |
|---|---|---|---|
| danmuObj | object | No | Danmaku data object, containing content and display attributes |
| setting | object | Yes | Danmaku settings |
Return Value: None
Detailed Description:
zwplayerimplements an internal Danmaku renderer. Once a Danmaku comment is obtained, calling this method will display it on the video screen.- Danmaku comments are typically relayed via a network Danmaku server.
zwplayeris not bound to any specific Danmaku relay server, nor does it specify a Danmaku transmission protocol. The user must obtain the Danmaku comments via their own method and call this function to display them on the player. - For the format of the
danmuObjobject, refer to Danmaku Object Format
4.3 buildDanmuControlbar
buildDanmuControlbar(parentId, className);
Description: Create a Danmaku input control toolbar.
| Parameter | Type | Optional | Description |
|---|---|---|---|
| parentId | string | Yes | ID of the parent element to contain the toolbar, a DIV element |
| className | string | Yes | CSS class to add to the top-level DIV element of the Danmaku toolbar |
Return Value: None Features:
- Provides a complete Danmaku interaction interface, including input, emojis, Danmaku settings, and toggling. Reusing this UI saves time on “reinventing the wheel” and is highly recommended.
- Adopts an independent UI component design, allowing flexible deployment anywhere on the page
- Avoids display issues caused by insufficient space in the player container
- Supports style customization for easy integration with different page styles
Detailed Description:
- If
parentIdis omitted or does not exist, the Danmaku toolbar will be created inside the player’s main control toolbar. If the space in the main control bar is too small, the Danmaku input toolbar will not be displayed. - The Danmaku toolbar already has the class
zwp_danmu-controlbar; styles can be further controlled via theclassNameparameter - This function must be called for
zwplayerto accept Danmaku input in fullscreen mode - For detailed information on Danmaku, please refer to Danmaku Settings.
5. Subtitles
5.1 addSubtitle
addSubtitle(subtitleUrl, pos, title);
Description: Add subtitles.
| Parameter | Type | Optional | Description |
|---|---|---|---|
| subtitleUrl | string/object | No | URL of the subtitle file / Local file object |
| pos | string | No | Subtitle position (‘1’ or ‘2’) |
| title | string | Yes | Readable name of the subtitle for user selection |
Return Value: None
Detailed Description:
- Supported subtitle formats: srt, vtt, json, bcc
- Subtitle position only supports ‘1’ (First Subtitle) and ‘2’ (Second Subtitle); other values will fail to load
zwplayersupports displaying two subtitles simultaneously (dual subtitles)- For details on subtitle settings, please refer to Subtitle Settings.
5.2 removeSubtitle
removeSubtitle();
Description: Remove all subtitles.
Parameters: None
Return Value: None
Detailed Description: Calling this function will remove all loaded subtitles from the player.
6. Lyrics (Music Mode)
Only available in music mode:
mode: 'music', ormode: 'auto'when auto-detected as audio. In other modesplayer.setLyricsisundefined. For full lyrics configuration (initial loading, LRC format, word-by-word sync), see Music Mode · Lyrics.
6.1 setLyrics
setLyrics(lrc);
Description: Dynamically replace or clear lyrics at runtime.
| Parameter | Type | Optional | Description |
|---|---|---|---|
| lrc | string / string[] / null | No | LRC text, array of LRC lines, lyrics file URL, or null/empty to clear |
Return Value: None
Detailed Description:
- LRC text (containing
[mm:ss]timestamps) → parsed and rendered directly - Array of LRC lines (e.g.
['[00:01.00]line one', '[00:03.50]line two']) → joined then parsed - A string without timestamps → treated as a lyrics file URL and loaded asynchronously;
onLyricsLoadedfires on success,onLyricsErroron failure - null / undefined / empty string → clears current lyrics
- After replacing, lyric highlighting and word-by-word sync automatically follow the new timeline
- Manual timeline offset (±0.5s) is controlled by buttons in the music panel, not by this method’s parameters
7. Audio Tracks (Dubbing)
Similar to subtitles, audio track switching and selection are handled uniformly by the player CC menu. Only two methods for adding and clearing are provided here. For complete usage instructions, see Audio Tracks Guide.
7.1 addAudioTrack
addAudioTrack(audioUrl, language, label);
Description: Add an external audio track (dubbing).
| Parameter | Type | Optional | Description |
|---|---|---|---|
| audioUrl | string | No | External audio file URL (mp3/m4a/aac/ogg/wav) |
| language | string | Yes | Language code (e.g. ja, zh, en) |
| label | string | Yes | Display name, takes priority over language |
Return Value: The id (number) of the newly added audio track, or null on failure.
Detailed Description: After adding, the dubbing panel in the CC menu will automatically refresh, allowing users to select and switch in the UI. Tracks can also be mounted in batch during initialization via the audioTracks configuration option.
7.2 clearAudioTracks
clearAudioTracks();
Description: Clear all external audio tracks and return to the original audio.
Parameters: None
Return Value: None
Detailed Description: Calling this function removes all mounted external audio tracks from the player and automatically switches back to the video’s original audio track.
8. Chapters
8.1 setChapters
setChapters(chapters);
Description: Set chapter information.
| Parameter | Type | Optional | Description |
|---|---|---|---|
| chapters | string/array/object/null | No | Chapter file url, chapter content text string, chapter list object, or chapter local file object |
Return Value: None
Detailed Description:
- If the
chaptersparameter is null, current chapter information will be removed - Supports multiple formats: chapter file url, chapter content text string (js string), or a parsed chapter list object (js array)
- For details on loading chapter information, please refer to Chapter Settings
9. State Management
9.1 notifyResize
notifyResize(width, height);
Description: Notify the player when its size changes.
| Parameter | Type | Optional | Description |
|---|---|---|---|
| width | string | No | New width (pixels or percentage) |
| height | string | No | New height (pixels or percentage) |
Return Value: None
Recommended Practice: Set the style of the DIV element associated with the player’s playerElm parameter to "width:100%;height:100%". This allows the player to resize automatically with the parent element without needing to call this method.
9.2 destroy
destroy();
Description: Destroy the player.
Parameters: None
Return Value: None
Detailed Description:
- After calling, the player will stop the current stream and completely clear all content from memory
- The player object cannot be used to call any methods afterwards