Skip to main content

Using the API

The iframe embed lets you embed your Vdocipher videos and control the player using Javascript. You have access to the essential methods and properties of the players. There are events that you can listen for and execute custom actions in your web application.

1. Adding the script

Add the following script to the html of your web page. This loads the interface that are used to establish communication with the video player. If this script is loaded on-demand later, make sure to wait for the load to complete before calling subsequent methods on the object.

<script src=""></script>

2. Get a reference to the iframe

Note: Assuming the API script (above) is already loaded, otherwise wrap all the below code this in a window.onVdoPlayerV2APIReady() method.

To begin communicating with the player, get a reference to the iframe element. This can be using DOM APIs such as querySelector() or using some view library such as useRef() of ReactJS or ElementRef of Angular.

const iframe = document.querySelector('iframe');

3. Establish communication with the iframe

The script in step 1 provides a VdoPlayer constructor on window object. This constructor returns

const player = VdoPlayer.getInstance(iframe);

// All DOM API supports on'play', function () {
console.log('Video is playing');

Complete Sample Code using the above


<script src=""></script>
const iframe = document.querySelector('iframe');
// Creating player instance
const player = VdoPlayer.getInstance(iframe);

// All DOM API supports on'play', function () {
console.log('Video is playing');

// VdoCipher Custom API
player.api.getTotalPlayed().then(function (data) {
console.log('Video playback: ', data);

VdoPlayer instance

VdoPlayer constructor returns the Player Interface containing two properties as follows

"video": (HTMLVideoElement),
"api": (VdocipherCustomAPI)

Video []

The is a reference of the video element* of the player, and supports most DOM operations of HTMLVideoElement.

List of supported api on

Sample code for player operations

OperationCodeReturn Type<void><void>

The video element is a proxy element. Most of the properties and methods are available to access except few which will have the constant value NOT_AVAILABLE_ON_API, and all methods are wrapped in the promise.

VdocipherCustomAPI [player.api]

These are the custom api, to interact with player apart from the DOM API. Checkout VdocipherCustomAPI to know more.