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, zwplayer will start playback using the internally stored original parameters
  • If the url parameter was not passed during the constructor call and the play method with a url parameter has never been called, the play call 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 play afterwards 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 undefined if the player has no media loaded
    • Returns Infinity if the duration of the media cannot be obtained

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. Danmaku (Bullet Comments) Functionality

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

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

  • zwplayer implements 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. zwplayer is 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 danmuObj object, refer to Danmaku Object Format

3.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 parentId is 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 the className parameter
  • This function must be called for zwplayer to accept Danmaku input in fullscreen mode
  • For detailed information on Danmaku, please refer to Danmaku Settings.

4. Subtitles

4.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
  • zwplayer supports displaying two subtitles simultaneously (dual subtitles)
  • For details on subtitle settings, please refer to Subtitle Settings.

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

5. Chapters

5.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 chapters parameter 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

6. State Management

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

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