Commands JS API


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

Commands ↓   Events

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

var player = new Playerjs({...});
console.log(player.api("id"));
player.api("play");

For some commands you can specify a parameter

player.api("play","URL");
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 or playlist updating a content without starting -
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
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 -
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
hlserror
dasherror
- - object error for HLS / DASH
hls
dash
- - object hls.js or dash.js (direct access to the plugin)
fix
unfix
- 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)
geo - json data of geolocation plugin
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){
   alert("ready");
}

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="https://site.com/video.html" 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.




2020 © PlayerJS

Login

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

Enterprise

Your name
Website
Email
Phone
Description
Order player

Restore password

Restore
Forgot email? Contact us