Skip to main content
All CollectionsDeveloper HubPlayer API
Single/Multiple Player Reference
Single/Multiple Player Reference
Updated over a week ago

Overview

AnyClip supports the option of embedding multiple players in a single page. In this configuration, each player acts individually, therefore, you will need to know how access and control each player individually.

To enable you to control each player individually, you can access a specific player reference using one of the following ways:

A) Using the getWidget method with the widgetID as the widget identifier:

If each player on the page has been assigned a widgetID, use the getWidget method to set the player reference. The widgetID is unique to each player,i.e., widget0, widget1, widget, etc.

For example:

// multi-players by widgetId 
var widget_A = window.anyclip.getWidget("001w000001Y8Vax_111");
var widget_B = window.anyclip.getWidget("001w000001Y8Vax_222");

You can then control the player widget using the widgetID to perform all relevant actions.

B) Using the widgets (players) array:

For example:

// multi-players in widgets array 
var widget_A = window.anyclip.widgets[0];
var widget_B = window.anyclip.widgets[1];

C) Using the getWidget method with the sessionID as widget identifier:

This option should be used if you have multiple widgets on the page, where each widget has the same widgetID.

You can obtain the session ID by subscribing to the playerReady event. The sessionID is unique to that session instance.

For example:

// multi-players by sessionID 
var widget_A = window.anyclip.getWidget(null, widget_1_sid);
var widget_B = window.anyclip.getWidget(null, widget_2_sid);

Controlling your players

After setting up the reference for each player on the page, you can then control each widget independently in your code.

For example:

// pause player A and start playing player B. 
widget_A.pause(); widget_B.play();

Player array

AnyClip maintains player object references in the window.anyclip.widgets array, which can be accessed on the page after the first player has been embedded (the first player creates this array). If only one player has been created on the page, you can always refer to it with window.anyclip.widgets[0].

var widget_1 = window.anyclip.widgets[0];
Did this answer your question?