0.0.2

Video Events

React to playback state changes — play, pause, ended, seeking, time update, volume change, buffering, and errors.

Video events fire in response to playback state changes. Each event handler receives an object with the current ScenaVideoState and the original browser Event:

interface ScenaVideoEventOptions {
  state: ScenaVideoState;
  event: Event;
}

The error event may carry an error field instead of event:

interface ScenaVideoEventOptionsWithError {
  state: ScenaVideoState;
  error: unknown;
}

Events

EventString valueWhen
ON_VIDEO_READYvideo:on-readyVideo metadata is loaded and ready to play
ON_VIDEO_CAN_PLAYvideo:on-can-playEnough data buffered to start playback
ON_VIDEO_PLAYvideo:on-playPlayback starts or resumes
ON_VIDEO_PAUSEvideo:on-pausePlayback is paused
ON_VIDEO_ENDEDvideo:on-endedPlayback reaches the end
ON_VIDEO_SEEKINGvideo:on-seekingVideo is seeking to a new position
ON_VIDEO_SEEKEDvideo:on-seekedSeek operation completes
ON_VIDEO_SEEK_STARTvideo:on-seek-startUser begins dragging the progress bar
ON_VIDEO_SEEK_ENDvideo:on-seek-endUser releases the progress bar
ON_VIDEO_TIME_UPDATEvideo:on-time-updateCurrent playback time changes
ON_VIDEO_VOLUME_CHANGEvideo:on-volume-changeVolume level or mute state changes
ON_VIDEO_STATE_CHANGEvideo:on-state-changeAny video state property changes
ON_VIDEO_LOAD_STARTvideo:on-load-startBrowser begins loading the video
ON_VIDEO_LOADEDvideo:on-loadedVideo data is fully loaded
ON_VIDEO_WAITINGvideo:on-waitingPlayback stalls due to buffering
ON_VIDEO_PROGRESSEDvideo:on-progressedBrowser downloads more video data
ON_VIDEO_ERRORvideo:on-errorA playback or loading error occurs

Usage

import { ScenaEvent } from '@retoo/scena';

instance.api.events.on(ScenaEvent.ON_VIDEO_PLAY, ({ state, event }) => {
  console.log('Playing, current time:', state.currentTime);
});

instance.api.events.on(ScenaEvent.ON_VIDEO_TIME_UPDATE, ({ state }) => {
  console.log('Time:', state.currentTime, '/', state.duration);
});

instance.api.events.on(ScenaEvent.ON_VIDEO_ENDED, ({ state }) => {
  console.log('Finished');
});

instance.api.events.on(ScenaEvent.ON_VIDEO_ERROR, (data) => {
  if ('error' in data) {
    console.error('Error:', data.error);
  }
});

Seek events

There are two levels of seek events:

  • ON_VIDEO_SEEKING / ON_VIDEO_SEEKED — native browser seek events, fire on any seek operation.
  • ON_VIDEO_SEEK_START / ON_VIDEO_SEEK_END — fire when the user interacts with the progress bar.
instance.api.events.on(ScenaEvent.ON_VIDEO_SEEK_START, ({ state }) => {
  console.log('User started seeking from', state.currentTime);
});

instance.api.events.on(ScenaEvent.ON_VIDEO_SEEK_END, ({ state }) => {
  console.log('User seeked to', state.currentTime);
});