mpvPlayer API v10.07

link https://mpvplayer.com/api/v10

Introduction

Welcome to mpvPlayer API Guide.

This Guide is supposed to clarify the way how you can work with mpvPlayer.com API.

Using the following documentation you can automate the most often actions with mpvPlayer.

Before you start

In the mpvPlayer Account you can create HTML5 players for your website. You can quickly build the desired video player in an online cabinet.

The player is downloaded as a single file mpvPlayer.js - just add it to your website:

<script src="//url.com/mpvPlayer.js" type="text/javascript"></script>

Add a player to your website

The player's script is simple placed in the head tag of the page and integration code for player container

<div id="mpvplayer"></div>

<script>
   var player = new mpvPlayer({id:"mpvplayer", file:"//url.com/v.mp4"});
</script>

The variables and options:

-file --URL to a video file or mpv Content Catalog
-poster --URL of the image on the start screen of the player
-title --title ща the video
-autoplay --auto start video (1 or 0)
-start --start playback from the specified second
-end --end playback on the specified second
-subtitle --URL of the subtitle

Authorization

To start using mpvPlayer API you have to use authorization process, which is available as several options:

  • Access_token with using permanent key is available for paid users.
  • For users without additional validation – username and password.
  • For users with Goggle Captcha validation.

Authorization by permanent token

You can get a permanent token when you click “Create new token” button located on a Acoount Space. Now we’re going to request one of mpvPlayer API methods, for instance

CURL:


Request:
$ curl -X POST\
-H "Content-type: application/json" '{"acess_token":"yourtoken"}'\ 
https://mpvplayer.com/api/v10/test

Response:
{
"status":"success",
"code":200
}		

Authorization by login and password

We request an auth_token from the server.

CURL:


Request:
$ curl -X POST\
-H "Content-type: application/json"\
'{"username":"yourbox@email.com","password":"yourpassword"}'\ 
https://mpvplayer.com/api/v10/login		

You will receive auth_token in server response if your login and password are correct.

Response:
{
"status":"success",
"code":200,
"auth_token":"ldtrf4o3gf59s148723gsxbq50"
}		

PHP:


<?php
include "mpvPlayerAPI.php";
$api = new mpvPlayerAPI("yourbox@email.com", "yourpassword");
$result = $api->login();
var_dump($result);
/*
bool(true)
*/
var_dump($api->getAuthToken());
/*
string(ldtrf4o3gf59s148723gsxbq50)
*/

Authorization by login and password with ReCaptcha

This option is a bit complicated but it is worth using it due to we are concerned about the security of your account

CURL:


Request:
$ curl -X POST\
-H "Content-type: application/json"\
-d '{"username":"yourbox@email.com","password":"yourpassword"}'\ 
https://mpvplayer.com/api/v10/login
Response:
{
"message":"Please verify your request via re captcha challenge",
"status":"error",
"code":406,
"errorCode":33
}

At first, you should get a unique page with Google captcha.

Request:
$ curl -X POST -H "Content-type: application/json"\
https://mpvplayer.com/api/v10/requestReCaptcha
Response:
{
"status":"success",
"code":200,
"challenge":"9c726b3ce8b34",
"captcha_url":"https://mpvplayer.com/api/v10/requestReCaptcha?id=9c726b3ce8b34"
}

Open captcha_url in your browser and proceed verification. After you receive a link to a unique page with Google captcha and re_captcha_challenge you should open this link, pass captcha, and get unique code re_captcha_response.

All received data you should add to your authorization request do not forget to provide correct user login and password for authorization:

Request:
$ curl -X POST\
-H "Content-type: application/json"\
-d '{"username":"yourbox@email.com","password":"yourpassword"\
"re_captcha_challenge":"9c726b3ce8b34",\
"re_captcha_response":"9c726b3ce8b349c726b3ce8b349c726b3ce8b34"}' \ 
https://mpvplayer.com/api/v10/login
Response:
{
"status":"success",
"code":200,
"auth_token":"ldtrf4o3gf59s148723gsxbq50"
}

PHP:

<?php
include "mpvPlayerAPI.php";
$api = new mpvPlayerAPI("yourbox@email.com", "yourpassword");
$result = $api->login();
var_dump($result);
/*
bool(false)
*/
var_dump($api->request('requestReCaptcha'));
/*
array(4) {
["status"]=>
string(7) "success"
["code"]=>
int(200)
["challenge"]=>
string(13) "807a330502f04"
["captcha_url"]=>
string(59) "https://mpvplayer.com/api/v10/reCaptcha.html?id=807a330502f04"
}
*/

<?php
include "mpvPlayerAPI.php";
$api = new mpvPlayerAPI("yourbox@email.com", "yourpassword");
$result = $api->login(null, null, "807a330502f04", "807a330502f04807a330502f04");
var_dump($result);
/*
bool(true)
*/
var_dump($api->getAuthToken());
/*
string(ldtrf4o3gf59s148723gsxbq50)
*/

Requests and commands

API Javascript

 

To control the player and requests via Javascript, use the api operator:

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

For some commands you can specify a parameter:

player.api("play","URL");

Request Commands chevron_right expand_more

Command Parameter Action Return
play URL or id

starting playback

false or true for id

file URL or file_id

updating a content without starting

-

pause -

pause playback

-

stop -

stop playback

-

mute -

mute sound

-

unmute -

unmute sound

-

toggle -

toggle playback

-

seek time in seconds

seek (after starting)

-

isfullscreen -

-

true or false

playing -

-

true or false

started -

-

true or false

time -

-

current time of playback

duration -

-

duration in seconds

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)

qualities -

-

available qualities

id -

-

id

subtitle URL

launching subtitle from the source

-

poster URL

displays the poster if the player is paused

true or false

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

adblock -

-

on or off AdBlock (false or true)

live -

-

is a live stream or not (true or false)

size -

-

player size (width/height)

chromecast -

-

true or false

How to know that the player is ready to work

You can catch the init event that the player sends after initialization.

Alsoyou can use the ready parameter with the function name that the player will call when it is ready.

Example:

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

Events

API Javascript

 

JS API allows you to receive events, request data and manage it from the outside.

By default, all events will come to the function mpvPlayerEvents with three arguments:

event event name;

id player ID;

data information data.

function PlayerjsEvents(event,id,info){
   if(event=="play"){
      alert(event);
   }
   if(event == "time"){
      console.log(event,id,info);
   }
}

Events tracking chevron_right expand_more

Event Description Returning data
init initialization

-

start first playback launching

-

play playback starting

-

pause playback pausing

-

stop playback stopping

-

end end of playback

-

finish end of playback including advertising

-

new launching new source

-

time playback time changed

time in seconds

duration playback duration changed

duration in seconds

seek seeking

time in seconds

mute sound is muted

-

unmute sound is unmuted

-

volume volume is changed

volume from 0 to 1

quality quality is changed

name of the current quality

audiotrack audio track is changed

name of the current audio track

subtitle subtitle is turned on

name of the current subtitle

fullscreen full screen is turned on

-

exitfullscreen exit from the full screen mode

-

buffering start buffering

-

buffered end of the buffering

-

error playback error

error code

height the height of the player has changed

value in pixels

Listeners

You can also catch events with listeners.

Example:

document.getElementById("player").addEventListener("play",onPlay);

Resources

post /login

 

This method allows you to recieve auth_token for a user. All requests to resources which requere authentication must be with query parameter auth_token.

For more details proceed to Security in this documentation.

curl -X POST \
  -H "Content-type: application/json"
  -d @body.json \
  https://mpvplayer.com/api/v10/login

Request Body chevron_right expand_more

application/json

application/json

ParameterTypeDescription
username*string
password*string

example: password

re_captcha_challengestring

example: 4fd7s3sddb3a9

re_captcha_responsestring

example: 4fd7s3sddb3a9asdasasd

Request Body

{
    "username":"test",
    "password":"pass",
}

200 OK chevron_right expand_more

application/json

application/json

ParameterTypeDescription
status*string

success

code*integer

200

auth_token*string

example: cb9tg4rt9lom9gb5i6tudgqlse

Response Body

{
    "status":"success",
    "code":200,
    "auth_token":"cb9tg4rt9lom9gb5i6tudgqlse"
}

400 Bad Request chevron_right expand_more

application/json

application/json

ParameterTypeDescription
status*string

error

code*integer

400

errorCode*integer
  • 3 - Incorrect param value
message*string

Invalid request params

Response Body

{
    "status":"error",
    "code":400,
    "errorCode":2,
    "message":"Invalid request params"
}

403 Forbidden chevron_right expand_more

application/json

application/json

ParameterTypeDescription
status*string

error

code*integer

403

errorCode*integer
  • 71 - Login attempts exceeded
  • 72 - Account banned
  • 73 - No allow access from network
  • 74 - Unknown login error
  • 75 - Illegal session IP
  • 76 - Account stolen
  • 77 - Network banned
message*string

example: Network banned

Response Body

{
    "status":"error",
    "code":403,
    "errorCode":77,
    "message":"Network banned"
}

406 Not Acceptable chevron_right expand_more

application/json

application/json

ParameterTypeDescription
status*string

error

code*integer

406

errorCode*integer
  • 33 - ReCaptcha required
message*string

example: Please verify your request via re captcha challenge

Response Body

{
    "status":"error",
    "code":406,
    "errorCode":33,
    "message":"Please verify your request via re captcha challenge"
}

post /requestReCaptcha

 

This method returns re_captcha_challenge and link on a page with Google recaptcha.

If you perform authorization from doubtful IP addresses you have to pass verification

curl -X POST \
   https://mpvplayer.com/api/v10/requestReCaptcha

200 OK chevron_right expand_more

application/json

application/json

ParameterTypeDescription
status*string

success

code*int

200

challenge*string

example: 4fd7s3sddb3a9

captcha_url*string

Response Body

{
    "status":"success",
    "code":200,
    "challenge":"4fd7s3sddb3a9",
    "captcha_url":" https://mpvplayer.com/api/v10/reCaptcha.html?id=4fd7s3sddb3a9"
}

403 Forbidden chevron_right expand_more

application/json

application/json

ParameterTypeDescription
status*string

error

code*integer

403

errorCode*integer
  • 71 - Login attempts exceeded
  • 72 - Account banned
  • 73 - No allow access from network
  • 74 - Unknown login error
  • 75 - Illegal session IP
  • 76 - Account stolen
  • 77 - Network banned
message*string

example: Network banned

Response Body

{
    "status":"error",
    "code":403,
    "errorCode":77,
    "message":"Network banned"
}

get /reCaptcha

 

This method returns an html page with Google captcha.

Parameters chevron_right expand_more

ParameterTypeDescription
Query
id*string

example: 4fd7s3sddb3a9

curl -X GET \
   https://mpvplayer.com/api/v10/reCaptcha?id=<value>

200 OK chevron_right expand_more

text/html

text/html

400 Bad Request chevron_right expand_more

application/json

application/json

ParameterTypeDescription
status*string

error

code*integer

400

message*string

Response Body

{
    "status":"error",
    "code":400,
    "message":"Id not found"
}

Security Schemes

Security Scheme custom_scheme

Custom Scheme

To start using API you need to have mpvPlayer user account. You can set access_token parameter while running any methods from this API. You can find the access_token on your Account Space

curl -X <method> \
  https://mpvplayer.com/api/v10/<path>