Commands JS API

The JavaScript API allows you to get player events, request data and manage it from the outside.

Requests and commands   Show events

The api operator is used to manage the player and get data.

var player = new Playerjs({...});

For some commands you can specify a parameter

Command Parameter Action Return
play - starting playback* -
play URL, playlist or id: starting playback of new source* false or true for id:
pause - pause playback -
toggle - toggle playback -
file URL, playlist or id:
update a source (no play, no preload) -
preload URL or playlist update a source (no play, but preload) -
stop - stop playback -
mute - mute sound -
unmute - unmute sound -
seek time in seconds seek (after starting) -
fullscreen - go to full screen mode** -
exitfullscreen - exit from full screen mode -
isfullscreen - - true or false
playing - - true or false
started - - true or false
time - - current time of playback
duration - - duration in seconds
muted - - true or false
volume nothing or volume level the command returns the volume level or sets the value (from 0 to 1)
volume level (from 0 to 1)
quality nothing or the serial number of the quality option (0,1,2...) - current quality
qualities - - available qualities
audiotrack nothing or the serial number (0,1,2...) launches audiotrack, switching by number works from version 9.7
current audiotrack
audiotracks - - available audiotracks
speed  nothing or the serial number of the speed option (0,1,2...) - current speed
id - - id of the player container
log - - debug log
screenshot - takes a screenshot false or base64
subtitles - - available subtitles
subtitle URL or the serial number (-1,0,1,2...) launching subtitle from the source or by number (-1 disables subtitles from version 12) -
poster URL displays the poster if the player is paused true or false
share - display share screen with social and embed buttons if this plugin enabled in the builder -
title text or nothing displays the title if there is such element enabled player.api("title","text"), or return current value  player.api("title") true or title value
playlist object [ ] or url updates playlist  true or false
playlist_id - return id of the played track from playlist id
playlist_title - return title of the played track from playlist title
playlist_folders - return the array with data of the playlist root folders array
playlist_length - return length of the current playlist number
push JSON
adds new items to the playlist, for example [{"file":"URL","title":"TEXT"}, {"file":"URL","title":"TEXT"}] -
invert - invert the playlist in reverse order -
autonext nothing, 0 or 1 autoplay the next file from playlist (1) or not (0) 0 or 1 with no parameter
playlistloop nothing, 0 or 1 loop playlist (1) or not (0) 0 or 1 with no parameter
next - play next file in the playlist -
prev - play previous file in the playlist -
loop nothing, 0 or 1 set loop playback 0 or 1
find file id open track from playlist by id and wait of the starting true or false
cuid cuid value updates the cuid parameter to remember the time -
showplaylist - show playlist -
moveplaylist id - move playlist outside of the player
scale transformation step or format or nothing changes the video scale (floating-point number) or aspect ratio for incorrectly encoded video (width:height, for example 4:3 or 16:9)
if no parameter is specified, it returns an array with a scale in width, height and coordinates if the video is dragged
points object [ ] updates the markup -
thumbnails link to the thumbnails file updates the thumbnails -
visibility - - precent of the player visibility
- - object error for HLS / DASH
- - object hls.js or dash.js (direct access to the plugin)
- manual switching of the player's fixed mode -
adblock - - on or off AdBlock (false или true)
live - - is a live stream or not (true or false)
size - - player size (width/height)
stretch nothing, 0 or 1 stretch the video to fill all screen 0 or 1
flip flips the video horizontally
geo - - JSON data of geolocation plugin
pip - swaps the primary and secondary streams -
cut 1, 0, interval or nothing controls the interface for creating a segment -
toolbar - show the toolbar if it is hidden -
destroy - Prepares the player for removal before cleaning the container -
* you can add the option seek player.api("play","url[seek:10]"); to start with the desired second. First launching on mobile with sound works only after the user gestures.

** on all platforms only due to user actions

The API is in a constant development process, if you have something missing - write to us via feedback.

How to know that the player is ready to work

You can catch the init event that the player sends after initialization. Also, from version 9.25, you can use the ready parameter with the function name that the player will call when it is ready.

var player = new Playerjs({id:"player", ready:"PlayerReady", file:"..."});
function PlayerReady(id){

How to get the players events

You can read about listening to player events here.

How to send commands to the player inside the iframe

There is a special way for this postMessage. To make it work, you need to enable in the settings. Plugins / API / postMessage for iframe. For example, iframe looks like this:

<iframe id="player" src="" type="text/html" width="640" height="360" frameborder="0" allowfullscreen=""></iframe>

To send him a command you need to pass an object with the command api

document.getElementById("player").contentWindow.postMessage({"api":"play"}, "*");

If you need to pass a parameter, then  set is added to the object.

document.getElementById("player").contentWindow.postMessage({"api":"volume","set":0.5}, "*");

* at the end means that you trust this iframe. If not, then you need to pass URI.

2018 - 2021 © PlayerJS


Restore password
Sign up
Log in

Sign up free

Sign up
By signing up, you agree to Terms of Service
Login if you have an account


Your name
Order player

Restore password

Forgot email? Contact us