method

1. Playback Control

1.1 play

play(url, isLive, useOldFlv);

Description: Start playback. Calling this method will begin a new playback session.

Parameter NameTypeOptionalDescription
urlstring/objectOptionalMedia stream URL address/local file object, see url parameter description
isLivebooleanOptionalSpecify whether the media stream is a live stream
useOldFlvbooleanOptionalWhether to use the legacy Flv playback interface

Return Value: None

Detailed Description:

  • If the player is currently in playing state, calling this method will reopen the media and start playback from the beginning

  • If the player is currently 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 existing original parameters internally

  • If the url parameter was not passed when calling the constructor and a play method with 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 will not clear any internal data in the player.

1.3 stop

stop();

Description: Stop the ongoing playback.

Parameters: None

Return Value: None

Detailed Description:

  • Stopping playback is different from pausing playback. Stopping playback will clear all internal data in the player and reset the player to its initial state

  • This player object can still call play subsequently to start a new playback session

1.4 resume

resume();

Description: Resume playback.

Parameters: None

Return Value: None

Detailed Description:

  • If the player is in pause state, continue playback from the current position

  • If the player is in stop state, start a new playback session

1.5 setplaystate

setplaystate(bPlaying);

Description: Set the playback state.

Parameter NameTypeOptionalDescription
bPlayingbooleanRequiredtrue: 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:

    • If the player currently has no media open, returns undefined

    • If the duration of the playing media cannot be obtained, returns Infinity

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

Parameter NameTypeOptionalDescription
timenumberRequiredThe time to seek to, in seconds (float)

Return Value: None

Limitation: Only valid for on-demand programs

3. Danmaku Function

3.1 setEnableDanmu

setEnableDanmu(bEnable);

Description: Turn danmaku (bullet comments) function on or off.

Parameter NameTypeOptionalDescription
bEnablebooleanRequiredtrue: Enable danmaku, false: Disable danmaku

Return Value: None

3.2 appendDanmu

appendDanmu(danmuObj, setting);

Description: Add danmaku.

Parameter NameTypeOptionalDescription
danmuObjobjectRequiredDanmaku data object, containing danmaku content and display attributes
settingobjectOptionalDanmaku settings

Return Value: None

Detailed Description:

  • zwplayer has an internal danmaku renderer. After obtaining a danmaku, call this method to display the danmaku on the video screen.

  • Danmaku is usually forwarded by a network danmaku server. zwplayer is not bound to any danmaku forwarding server, nor does it specify which danmaku transmission protocol to use. Users obtain danmaku through their own methods and then call this function to display it on the player.

  • For the format of the danmaku object danmuObj, see Danmaku Object Format

3.3 buildDanmuControlbar

buildDanmuControlbar(parentId, className);

Description: Create a danmaku input control bar.

Parameter NameTypeOptionalDescription
parentIdstringOptionalParent element ID that contains the control bar, DIV element
classNamestringOptionalCSS class added to the top-level DIV element of the danmaku control bar

Return Value: NoneFeature Highlights:

  • Provides a complete danmaku interaction interface, including input danmaku, emoticons, danmaku settings and on/off switches. Reusing this UI can save time from "reinventing the wheel", highly recommended.

  • Adopts independent UI component design, can be flexibly deployed at any position on the page

  • Avoids display issues caused by insufficient player container space

  • Supports style customization, convenient for integration with different page styles

Detailed Description:

  • If parentId is omitted or does not exist, the danmaku control bar will be created inside the player main control toolbar. If the player main control bar space is too small, the danmaku input control bar will not be displayed.

  • The danmaku control bar already has the zwp_danmu-controlbar class, and styles can be further controlled through the className parameter

  • This function must be called for zwplayer to be able to input danmaku in fullscreen mode

  • For detailed information about danmaku, please see Danmaku Settings.

4. Subtitles

4.1 addSubtitle

addSubtitle(subtitleUrl, pos, title);

Description: Add subtitles.

Parameter NameTypeOptionalDescription
subtitleUrlstring/objectRequiredSubtitle file URL/local file object
posstringRequiredSubtitle position ('1' or '2')
titlestringOptionalReadable name of the subtitle, convenient for user selection

Return Value: None

Detailed Description:

  • Supported subtitle formats: srt, vtt, json, bcc

  • Subtitle positions only support '1' (primary subtitle) and '2' (secondary subtitle). Other values cannot be loaded

  • zwplayer supports displaying two subtitles simultaneously (dual subtitles)

  • For detailed subtitle settings, please see Subtitle Settings.

4.2 removeSubtitle

removeSubtitle();

Description: Remove all subtitles.

Parameters: None

Return Value: None

Detailed Description: Calling this function removes all loaded subtitles from the player.

5. Chapters

5.1 setChapters

setChapters(chapters);

Description: Set chapter information.

Parameter NameTypeOptionalDescription
chaptersstring/array/object/nullRequiredChapter file url, chapter content text string, or chapter list object, or chapter local file object

Return Value: None

Detailed Description:

  • If the chapters parameter is null, the current chapter information will be removed

  • Supports multiple formats: chapter file url, chapter content text string (js string), or already parsed chapter list object (js array)

  • For detailed chapter information loading, please see Chapter Markers Settings

6. State Management

6.1 notifyResize

notifyResize(width, height);

Description: Notify the player when player dimensions change.

Parameter NameTypeOptionalDescription
widthstringRequiredNew width (pixels or percentage)
heightstringRequiredNew 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%", so the player can automatically change with the parent element dimensions without calling this method.

6.2 destroy

destroy();

Description: Destroy the player.

Parameters: None

Return Value: None

Detailed Description:

  • After calling, the player will stop playing the current stream and completely clear all content from memory

  • The player object cannot be used to call any methods subsequently

 

Catalog Navigation