Player API

API Reference

VXDK provides a simple API to interact with the player. You can use the API to control the playback, listen to events, and get the current state of the player.

Methods

MethodDescription
loadLoads playback of the video in source
playStarts playback
togglePlayToggle (play/pause) playback of video
replayPlays the video from the beginning.
pausePauses playback of video
isPlayingReturns true if video is currently playing
setSourceSets the source of the video
stopStops playback of video
setVolumeSets volume of the video
getVolumeReturns current volume of the video
muteMutes the video
unmuteUnmutes video
toggleMuteToggles (mute/unmute) video
isMutedReturns true if audio is muted
seekToMethod for seeking to time in video
seekToPercentageMethod for seeking to a percentage of the video
getCurrentTimeReturns the current time of the playback
getDurationReturns duration of video playback
getBufferedPercentageReturns the total percentage percetage
isLiveReturns true if it's live stream
setLevelSets quality level for video playback if available
getCurrentLevelReturns the current quality level from playback
getLevelsReturns all available quality playback getLevels
isAutoLevelEnabledReturns true if ABR is set to 'auto'
enterFullscreenMethod to enter fullscreen mode
exitFullscreenMethod to exit fullscreen mode
toggleFullscreenToggles fullscreen mode
isFullscreenReturns true if vxdk is in fullscreen
setPlaybackRateSets playback speed of the video
getPlaybackRateReturns current playback speed of the video
enterPipEnter picture-in-picture mode
exitPipExist picture-in-picture mode
togglePipToggles picture-in-picture mode
isPipReturns true if vxdk is in picture-in-picture mode
getContextReturns the current context of the player
getStateReturns the current state of VXDK
getPluginReturns a instantiated plugin within VXDK
getPluginByNameReturns a initialized plugin within VXDK
getOptionsReturns the current initialized options of the player
getAutoPlayGets autoplay setting.
getVersionReturns VXDK version number
getRootElementReturns root element for vxdk
getWidthReturns the current width of the VXDK
getHeightReturns the current height of the VXDK
destroyDestroy and cleans up vxdk

Events

The vxdk player emits various events that you can listen to and handle using the on method. To remove a listener, use the off method.

Usage

You can listen to events using the on method and specifying the event name or the enum value.

// Using the enum value
vxdk.on(PLAYBACK_EVENT.PLAYING, () => {
  console.log('Playback has started');
});
 
// Using the event name
vxdk.on('playback.ended', () => {
  console.log('Playback has ended');
});

Playback Events

These events are related to the playback state and progress of the media. The playback events will be prefixed with playback.. You can also use the PLAYBACK_EVENT enum to listen to these events.

EventDescription
loadstartFired when the browser has started to load the resource.
loadedmetadataFired when the metadata has been loaded.
playFired when playback has begun.
pauseFired when playback has been paused.
playingFired when playback is ready to start after having been paused or delayed due to a lack of data.
endedFired when playback has stopped because the end of the media was reached.
waitingFired when playback has stopped because of a temporary lack of data.
timeupdateFired when the time indicated by the currentTime attribute has been updated.
duration.changedFired when the duration attribute has been updated.
buffered.changedFired when the amount of buffered media changes.
autolevel.changedFired when the automatic quality level changes.
levels.loadedFired when the available quality levels are loaded.
level.changedFired when the current quality level changes.
audio.changedFired when the audio track changes.
volume.changedFired when the volume has changed.
rate.changeFired when the playback rate has changed.
errorFired when an error occurred while fetching the media data, or the type of the resource is not a supported media format.
destroyFired when the player instance is destroyed.

Context Events

These events are related to the context state and configuration. The context events will be prefixed with context.. You can also use the CONTEXT_EVENT enum to listen to these events.

EventDescription
initializingFired when the context is initializing.
plugins.loadedFired when all plugins are loaded.
plugins.connectedFired when plugins are connected.
plugins.disconnectedFired when plugins are disconnected.
playback.adapter.loadedFired when the playback adapter is loaded.
storage.loadedFired when the storage is loaded.
readyFired when the context is ready.
dimension.changedFired when the dimensions of the player change.
fullscreen.changedFired when the fullscreen state changes.
pip.changedFired when the picture-in-picture state changes.
destroyFired when the context is destroyed.
state.changedFired when the state of the context changes.
options.changedFired when the options of the context change.

State

Vxdk provides an easy API to allow to get the current state of the playback. This is ideal for easy implementation on other front-end frameworks.

Use more specific event changes if you don't need the full state of VXDK.

Usage

You are able to get the current state of the player at any time.

vxdk.getState();

You can also listen for state changes.

vxdk.on(CONTEXT_EVENT.STATE_CHANGED, () => {
  console.log(vxdk.getState());
})
 

State data

The state data will contain the following properties:

PropertyTypeDescription
readybooleanVxdk is ready
livebooleanPlayback type is live
hdbooleanPlayback quality is HD
focusedbooleanMain container element is focused
waitingForUserbooleanIts waiting for user to start playback
playingbooleanIs playing
pausedbooleanIs paused
bufferingbooleanIs buffering
startedbooleanPlayback has started
endedbooleanPlayback has ended
currentTimenumberCurrent playback time
durationnumberDuration of video playback
optionsOptionCurrent options for playback
bufferedPercentagenumberPercentage of current buffer
volumenumberCurrent volume
mutedbooleanIs muted
playbackRatenumberCurrent playback rate
fullscreenbooleanIs fullscreen
pipbooleanis picture-in-picture enabled
levelsarrayAvailable quality levels
levelnumberCurrent selected level
levelAutoSwitchbooleanIs level auto switch enabled
audioLanguagesarrayCurrent available audio languages
widthnumberCurrent width of the player
heightnumberCurrent height of the player

../components/table