Skip to main content

Overview

The player emits various events that are processed by its RootController. You can listen to these events after they are processed. Events have a set of fields that are always present and some events contain additional fields.
Example event
{
  id: "51178a37-d5a7-4d75-9a12-a26eabfe7839",
  type: "PressedPlaylistItem",
  description: "A playlist item was pressed.",
  index: 3,
  initiatedBy: "user",
  emittedFrom: "inline-player",
  status: "handled",
  createdAt: "2023-01-01T12:00:00.000Z",
  processedAt: "2023-01-01T12:00:00.005Z",
  changedProps: {
    contentIndex: { previousValue: 0, currentValue: 3 },
  },
}
For the above example, the ‘index’ field additional and is specific to the PressedPlaylistItem event. All of the other fields are present in every event. Their schema is explained below.

Event schema

  • id: a random UUID generated and assigned to the event at creation
  • type: the type of event, see the table below for a listing of event types
  • description: a short human-readable description of the event
  • initiatedBy: who initiated the event, one of: { user, media, browser, media-session-api, google-ima-sdk }
  • emittedFrom: which interface emitted the event, one of: { inline-player, bottom-widget, segment, segment-widget }
  • status: the status of the event, one of: { handled, ignored-due-to-advert, ignored-due-to-scrubbing, ignored-due-to-precedence }
  • createdAt: the time when the event was created in simplified extended ISO 8601 format
  • processedAt: the time when the event was processed in simplified extended ISO 8601 format
  • changedProps: an object listing the player properties that were changed by the event
It is recommended to not depend on changedProps and additional event fields (e.g. index) since these might change. Instead, please query the player props directly using the Player SDK when listening to events.

Event types

The following table lists all event types emitted by the player. Initiators denoted with a plus (+) can also be initiated by media-session-api, e.g. using playback controls on a phone lock screen. Initiators denoted with a star (*) can also be initiated by google-ima-sdk when VAST adverts are playing. To inspect the events further, it is recommended you listen to "<any>" event and console log them.
TypeInitiatorDescription
IdentifiersChangedbrowserThe Player’s content identifiers changed.
ContentAvailablebrowserContent was loaded into the player and is ready to be played.
NoContentAvailablebrowserNo published and processed content is available for the identifiers.
FullScreenModeUpdatedbrowserThe browser entered or exited full screen mode.
PressedPlayuser+The play button was pressed.
PressedPauseuser+The pause button was pressed.
PressedChangeRateuserThe change playback rate button was pressed.
PressedEnterOnChangeRateuserThe enter key was pressed while change playback rate was focussed.
PressedSpaceOnChangeRateuserThe space key was pressed while change playback rate was focussed.
PressedUpOnChangeRateuserThe up key was pressed while change playback rate was focussed.
PressedRightOnChangeRateuserThe right key was pressed while change playback rate was focussed.
PressedDownOnChangeRateuserThe down key was pressed while change playback rate was focussed.
PressedLeftOnChangeRateuserThe left key was pressed while change playback rate was focussed.
PressedPrevSegmentuser+The previous segment button was pressed.
PressedNextSegmentuser+The next segment button was pressed.
PressedSeekBackuser+The seek backward button was pressed.
PressedSeekAheaduser+The seek ahead button was pressed.
PressedPrevTrackuser+The previous track button was pressed.
PressedNextTrackuser+The next track button was pressed.
PressedAdvertLinkuserThe advert link was pressed to open the click-through URL in a new tab.
PressedAdvertButtonuserThe advert button was pressed to open the click-through URL in a new tab.
PressedAdvertImageuserThe advert image was pressed to open the advert in a new tab.
PressedAdvertVideouserThe video background was pressed to open the advert in a new tab.
PressedBeyondWordsuserThe BeyondWords logo was pressed to open the BeyondWords website in a new tab.
PressedSourceUrluserThe source URL button was pressed to open the source article in a new tab.
VisibilityChangeduserThe player was scrolled into or out of view.
PressedVideoBackgrounduserThe video background was pressed.
PressedEnterOnProgressBaruserThe enter key was pressed while the progress bar was focussed.
PressedSpaceOnProgressBaruserThe space key was pressed while the progress bar was focussed.
PressedEnterOnProgressCircleuserThe enter key was pressed while the progress circle was focussed.
PressedSpaceOnProgressCircleuserThe space key was pressed while the progress circle was focussed.
PressedLeftOnProgressBaruserThe left key was pressed while the progress bar was focussed.
PressedRightOnProgressBaruserThe right key was pressed while the progress bar was focussed.
PressedLeftOnProgressCircleuserThe left key was pressed while the progress circle was focussed.
PressedRightOnProgressCircleuserThe right key was pressed while the progress circle was focussed.
PressedProgressBaruserThe progress bar was pressed at some ratio.
ScrubbedProgressBaruser+The user pressed on the progress bar then dragged.
FinishedScrubbingProgressBaruserThe user let go after scrubbing the progress bar.
PressedMaximizeuserThe maximize button was pressed.
PressedPlaylistItemuserA playlist item was pressed.
PressedDownloaduserThe download button next to a playlist item was pressed.
PressedTogglePlaylistuserThe toggle playlist button was pressed.
PressedCloseWidgetuserThe close widget button was pressed.
PressedSegmentuserThe user pressed on a segment in the article.
HoveredSegmentUpdateduserThe user hovered over a different segment in the article.
CurrentSegmentUpdatedmediaThe media’s current segment was updated.
MetadataLoadedmediaThe media finished loading its metadata.
MediaLoadedmediaThe media finished loading its first frame of data.
MediaSeekedmediaThe media completed the seek operation.
DurationUpdatedmedia*The media’s duration was updated.
CurrentTimeUpdatedmediaThe media’s current time was updated.
PlaybackPausedmedia*The media became paused at its current playback time.
PlaybackRateUpdatedmediaThe media’s playback rate was updated.
PlaybackPlayingmediaThe media began playing from its current playback time.
PlaybackEndedmedia*The media finished playing because it reached the end.
PlaybackNotAllowedmediaThe media cannot play because there was no user event.
PlaybackErroredmedia*The media failed to play.
CompanionAdvertChangedmedia*The companion advert associated with the VAST advert changed.

Listening to events

The player emits events in response to user actions, playback time updates, entering full screen, etc. You can listen to these events in your JavaScript code:
const player = BeyondWords.Player.instances()[0];

player.addEventListener("<any>", console.log);
The code above registers an event listener that listens to any event and logs it to the console. If you only want to listen to a single event type, provide its name:
player.addEventListener("PressedPlay", console.log);

player.addEventListener("PlaybackEnded", console.log);
Events contain a standard set of fields such as type and createdAt and some contain additional fields. Please refer to Event schema and Event types for a full listing of event types and their fields.

Cleaning up

The return value of addEventListener is a string that is a handle to the listener. This allows you remove the listener, for example, if a React component is unmounted:
useEffect(() => {
  const listener = player.addEventListener("<any>", console.log);
  return () => player.removeEventListener("<any>", listener);
}, []);
Or when your Svelte component is unmounted:
onMount(() => {
  const listener = player.addEventListener("<any>", console.log);
  return () => player.removeEventListener("<any>", listener);
});
Otherwise, the callback function will continue to be called which may result in an error in your application.