Skip to main content

Event Interface

Listen to events

The player offers the possibility to listen to the event interface easily.

To achieve that, add listeners by using the on(), one() and off() methods on the player instance.

The native event object coming from the video tag is forwarded as event data, plus some data in the "detail" attribute for some events only. Those data are listed in the reference below.

A complete events list can be found as the static eventsList property of a player instance.

Player instance object
{
setup: Function,
load: Function,
destroy: Function,
api: Object,
eventsList: Object
}
caution

Don't use event names to add event listener, add events listeners as follows:

(async () => {
const myPlayer = await oberplayer(document.querySelector('#player_container'));

// list the event's names
console.log(player.eventsList);

myPlayer.on(player.eventsList.READY, () => {
console.log('Player is ready to play');
});
myPlayer.on(player.eventsList.TRYINGTOPLAY, () => {
console.log('Player is trying to play');
})
myPlayer.on(player.eventsList.TRYINGTOPLAY, () => {
console.log('Player is trying to play');
})
myPlayer.on(player.eventsList.BUFFERING, () => {
console.log('Player is buffering');
})
myPlayer.on(player.eventsList.PAUSE, () => {
console.log('Player is paused');
})
myPlayer.one(player.eventsList.TIME, (evt) => {
console.log('Player is running, this event will be triggered many time so be carefull', evt.detail);
})
myPlayer.setup({
playlist: [
{
videoUrl: 'https://cdn.oberplayer.com/fixtures/mp4/bbb_27s_4k.mp4'
}
]
});
})();

Event reference


TRYINGTOPLAY

Description

Triggered when the player tries to play the given videoUrl. As the name suggests, this event can be followed by an error if the video file is in 404 for example.

No returned detail event data

CANPLAY

Description

Triggered when the player knows that the given videoUrl can be technically played.

No returned detail event data

FIRSTPLAY

Description

Triggered when the video succeeds in beeing played. It can only be triggered once.

No returned detailevent data

PLAY

Description

Triggered each time the video is beeing played.

No returned detail event data

PAUSE

Description

Triggered each time the video is being paused.

No returned detail event data

AIRPLAY

Description

Triggered when AirPlay devices availability changed (Apple devices only).

Event detail data

NameType
availabilityBoolean

CAST

Description

Triggered when Chromecast device availability changed (Chromium-based browsers only).

Event detail data

NameType
availabilityBoolean
activeBoolean

FULLSCREEN

Description

Triggered when the fullscreen state is updated.

Event detail data

NameType
isFullScreenBoolean

VOLUME

Description

Triggered when the volume is updated. The value ranges from 0 to 100.

Event detail data

NameType
volumeNumber

MUTE

Description

Triggered when the mute status is updated.

Event detail data

NameType
isMutedBoolean
info

This value is independent of the volume value.

SEEKING

Description

Triggered when the video time position is updated.

Event detail data

NameType
currentTimeNumber
durationNumber

SEEKED

Description

Triggered when the video has finished its seeking action.

Event detail data

NameType
currentTimeNumber
durationNumber

ENDED

Description

Triggered when the video has played to the end.

No returned detail event data

BUFFERING

Description

Triggered when the video is buffering data to be able to start or to continue playing.

No returned detail event data

TIME

Description

Triggered on a device-based frequency when the current player position has been updated.

Event detail data

NameType
currentTimeNumber
durationNumber

METADATA

Description

Triggered when the video duration is available.

Event detail data

NameType
durationNumber

VIDEOTRACKS

Description

Triggered when the qualities (video tracks) of an HLS or a DASH video are available.

Event detail data

NameType
videoTracksArray of videoTrack objects

videoTrack object structure

NameTypeDescription
widthNumberin pixels
heightNumberin pixels
bitrateNumberin kbps
nameString
selectedBoolean
idString
hdBooleantrue if the video has a width >= 1920 and < 3840. A "HD" icon is displayed in the player
uhdBooleantru if the video has a width >= 3840. A "4K" icon is displayed in the player
hdrBooleantrue if the video is in High Dynamic Range. . A "HDR" icon is displayed in the player

VIDEOTRACKASKED

Description

Triggered when a video track update has been programmatically asked.

Event detail data for a no-auto quality

NameTypeDescription
widthNumberin pixels
heightNumberin pixels
bitrateNumberin kbps
abrBooleantrue if adaptive bitrate streaming technology is used

Event detail data for auto quality

NameTypeDescription
abrBooleantrue if adaptive bitrate streaming technology is used

VIDEOTRACKCHANGED

Description

Triggered when the video track has been changed.

Event detail data for a no-auto quality

NameTypeDescription
widthNumberin pixels
heightNumberin pixels
bitrateNumberin kbps
abrBooleantrue if adaptive bitrate streaming technology is used

AUDIOTRACKS

Description

Triggered when the audio tracks of an HLS or a DASH video are available.

Event detail data

NameType
audioTracksArray of audio objects

audioTrack object structure

NameTypeDescription
languageStringTwo letters lowercase country code ( fr, de, en...)
nameString
roleStringset to public.accessibility.describes-video is the track is an audio description
selectedBoolean
idString

AUDIOTRACKASKED

Description

Triggered when an audio track update has been asked.

Event detail data

NameTypeDescription
languageStringTwo letters lowercase country code ( fr, de, en...)
roleStringset to public.accessibility.describes-video is the track is an audio description

TEXTTRACKS

Description

Triggered when the text tracks (subtitles or captions) of an HLS or a DASH video are available.

Event detail data

NameType
textTracksArray of textTrack objects

textTrack object structure

NameTypeDescription
languageStringTwo letters lowercase country code ( fr, de, en...)
kindStringcan be caption or subtitle
nameString
selectedBoolean
idString
rolesArraySee list below for possible values
info
  • public.accessibility.transcribes-spoken-dialog
  • public.accessibility.describes-music-and-sound
  • public.easy-to-read
  • public.accessibility.describes-video

TEXTTRACKASKED

Description

Triggered when a text track update has been asked.

Event detail data

NameTypeDescription
languageStringTwo letters lowercase country code ( fr, de, en...)
rolesArray

VIDEOTYPE

Description

Triggered to let you know whether the current video is a livestream.

Event detail data

NameTypeDescription
isLiveBooleanDescribes if the stream is a livestream or not

READY

Description

Triggered when the player's DOM has been rendered. From this point you can safely modify it.

No returned detail event data

NEXT

Description

Triggered when the player tries to load the next item of a playlist.

Event detail data

NameTypeDescription
comingFromClickBooleanDescribes if the event has been human or programmatically triggered

PREVIOUS

Description

Triggered when the player tries to load the previous item of a playlist.

Event detail data

NameTypeDescription
comingFromClickBooleanDescribes if the event has been human or programmatically triggered

LOAD

Description

Triggered when the player tries to load a video.

No returned detail event data