Polyv Help Center

Help Center

Player API

Updated: 2025-09-25 17:24:53

Player Properties

Parameter Type Default Value Platform Support Description
wrap string / HTMLElement - PC/Mobile DOM element or CSS selector on the page where the player should be loaded
width number / string 100% PC/Mobile Player width
height number / string auto PC/Mobile Player height
uid string - PC/Mobile User ID, i.e., userId from account information
vid string - PC/Mobile Channel ID
coverImg string - PC/Mobile Custom warm-up image
autoplay boolean - PC/Mobile Whether to autoplay, defaults to the live broadcast backend setting.
Note: Autoplay may fail on both PC and mobile. See FAQ - Autoplay for reasons.
isAutoChange boolean false PC/Mobile Automatically switch between live/playback (latest live recording)
vodsrc string - PC/Mobile Playback video URL
hasControl boolean false Mobile Whether to show the default control bar skin. If false, uses the browser's default skin.
Note: Mobile only. Due to system browser hijacking, the browser's default skin is forced; some browsers may ignore this setting.
It is recommended to use this parameter together with skin_type: 'black'
skin_type string - Mobile Skin style: set to 'black' for a dark skin.
Note: Mobile only
language number 0 PC/Mobile Player language, 0 for Chinese, 1 for English
df number - PC/Mobile Default video quality for multi-bitrate, 0: standard, 1: HD, 2: Full HD
banMultirate boolean false PC/Mobile Disable multi-bitrate functionality
banMuteTips boolean false PC Hide mute tips. See FAQ - Autoplay - Mute Playback for details.
Note: PC only
banRightMenu boolean false PC Disable right-click menu
banRate boolean false PC/Mobile Disable playback speed functionality
danmuEnable boolean false PC/Mobile Enable danmaku (requires backend switch)
showDanmu boolean - PC/Mobile Whether to show danmaku
banDanmuBtn boolean - PC/Mobile Disable danmaku button
skinConfig object - PC/Mobile Skin settings
streamStop: Image URL displayed when live stream stops
streamStopTxt: Text displayed when live stream stops
streamPause: Image URL displayed when live stream pauses
bgColor: Background color
playBtnImg: Play button image URL
showPlayBtn: Whether to show the play button
showFullScreen: Whether to show the fullscreen button
showProgress: Whether to show the progress bar
showVolumeBtn: Whether to show the volume button (default: false, mobile only)
webPageFullScreen boolean false Mobile Whether to use webpage fullscreen
Note: Mobile only
fullScreenOrientation string none Mobile Webpage fullscreen orientation: portrait, landscape, none
Note: Mobile only
banLivePause boolean false PC/Mobile Hide the pause button during live streaming. Does not apply to playback. Mobile requires hasControl and skin_type to be used together.
useHls boolean - PC Force HLS for live streaming
useHlsPlay boolean - Mobile Use HLS for live streaming only
usePanorama boolean - PC/Mobile Enable live VR mode

Player Methods

Method Parameters Callback Parameters Platform Support Description
j2s_resumeVideo PC/Mobile Resume video playback
j2s_pauseVideo PC/Mobile Pause video playback
j2s_stopVideo PC/Mobile Stop video playback
j2s_seekVideo time:number PC/Mobile Seek to a specific position in the video (playback)
j2s_setVolume volume:number PC/Mobile Set player volume, range 0-1. Note: iOS does not support changing video volume.
j2s_getCurrentTime time:number PC/Mobile Get the current video time
j2s_showBarrage PC/Mobile Show danmaku
j2s_hideBarrage PC/Mobile Hide danmaku
j2s_addBarrageMessage data:Object PC/Mobile Send a danmaku message. See feature usage - Danmaku for details.
j2s_changeLevel hd:number PC/Mobile 0/1/2: Smooth/HD/Full HD
j2s_changeRate rate:number PC/Mobile 1.0/1.25/1.5/2.0
changeLine(line) line:number PC/Mobile 0/1: Line 1/Line 2
getDuration number PC/Mobile Get the video duration
getCurrentLevel number PC Get the current video quality
getCurrentRate number PC Get the current playback speed
getCurrentLine number PC Get the current line index
j2s_resetStream PC/Mobile Refresh the live stream (near buffer end)
toggleFullscreen PC Toggle fullscreen/exit fullscreen
showVolumePanel boolean PC Show/hide the volume bar (UI)
setVideoMuted isMuted:boolean Mobile Mobile only. Mute/unmute the video. true to mute, false to unmute.
destroy PC/Mobile Destroy the player

Example

player.j2s_resumeVideo();

Player Events

Event Name Callback Parameters Type Platform Support Description
s2j_onInitOver / / PC/Mobile Player initialization complete
s2j_onLoadedMetadata cid string PC Triggered after loadedmetadata (includes cid, etc.)
s2j_onApiStatus streamStatus string PC/Mobile Live stream status, triggered every 10s. Values: live/end/stop
s2j_volume volume number PC/Mobile Triggered when player volume changes, range 0-1
s2j_onStartPlay cid string PC/Mobile Triggered when playback starts, fires only once
s2j_onPlay cid string PC/Mobile Triggered when playback starts
s2j_onPause cid string PC/Mobile Triggered when paused
s2j_onSeek / / PC/Mobile Triggered when seeking. Note: Callback parameters differ between PC and mobile; mobile only gets the time after seeking completes.
s2j_onOver cid string PC/Mobile Triggered when playback ends
s2j_onPlayerKeyUp keyCode number PC Keyboard key listener. Note: PC only
s2j_onLevelsChanged cid, hd string, number PC/Mobile Triggered when video quality changes. hd: 0/1/2 (Smooth/HD/Full HD)
onLineChanged cid, line string, number PC/Mobile Triggered when line changes. line: 0/1 (Line 1/Line 2)
s2j_onPlayerError errorCode string PC Triggered on playback error
s2j_barrageStatus status string PC Danmaku toggle change: on/off
s2j_broadcastBarrageMsg msg string PC Triggered when a danmaku message is sent
onLinesDataUpdate linesData Array PC Line data update ([{type,index}])
onLevelsDataUpdate levelsData Array PC Quality data update ([{type,index}])
onTimeupdate time number PC Playback/timeshift progress callback
timeupdate time number Mobile Playback/timeshift progress callback
onAutoPlay cid, autoplay string, boolean PC Autoplay detection result callback
HEAD_AD_CLICKED data object PC/Mobile Pre-roll ad click
STOP_AD_CLICKED data object PC/Mobile Pause ad click
playerLoading boolean boolean PC/Mobile First screen/buffer loading state
flvError {err, retryTime} object PC flv.js error information and retry count
volumechange object object Mobile Volume change callback. Only triggered when volume is changed via j2s_setVolume or setVideoMuted. Adjusting the device's physical volume does not trigger this event. Note: iOS does not support changing video volume.

Example

player.on(eventName, (e) => {
 console.info(`播放器触发${eventNmae}事件, 回调参数为:`, e);
});

Player Error Codes

Error Code Description
LIVE-#001 Invalid parameters
LIVE-#002 Abnormal user status
LIVE-#003 Service expired
LIVE-#004 Live channel does not exist or is closed
LIVE-#005 Insufficient available live minutes
LIVE-#006 Channel has reached maximum concurrent viewers
LIVE-#007 Website whitelist restriction
LIVE-#008 Website blacklist restriction
LIVE-#009 Region whitelist restriction
LIVE-#010 Region blacklist restriction
LIVE-#011 Live playback configuration file load/parse error
LIVE-#012 Authorization or watermark load/parse error or failure
LIVE-#014 Exceeded maximum concurrent users for the account
LIVE-#015 Player detected stream hijacking
LIVE-#016 Player prohibits popup playback
LIVE-#022 Watermark deleted or modified
联系客服,在线咨询