Source/Playback API

At the moment the Source API is quite limited, but it is constantly extended to cover everything a player will need. The base of every source api includes the following

interface SourceApiBase {
  logLevel: LogLevel; // getter/setter for log level
  loadControl: LoadControl; // getter/setter for LoadControl
  readonly id: string; // generated id
  readonly events: EventBus<EmptyObject>; // event bus of the source

This is additionally extended with certain packages explained bellow.

We are also able to subscribe to all of the source related events using event bus under events namespace. You can checkout all of the events available through SourceAPI in API documentation.

LoadControl api

We are able to define what we want our player to load by setting a load control. This can be used through the API, or passed in to source options once adding a source.

// ...
enum LoadControl {
  Nothing = 0,
  Metadata = 1,
  Data = 2,

const sourceApi = player.sources.add(sourceConfig);
// Change loadControl from Data to Nothing
sourceApi.loadControl = LoadControl.Nothing;

By default, the source load control is set to Data (loads both manifests and segments), but we can change this to metadata only (loads only manifests) or nothing to prevent it from loading any data.


Additionally, other packages will extend this SourceApi, for eg. one of the default packages PlaybackApiPackage will add play and pause methods. As we are working more on the player, this will be extended to contain additional playback methods.

const sourceApi = player.sources.add(sourceConfig);
// We are able to access this source api directly
// or accessing it through player.sources.list();

This package also exposes additional events on (EventBus).

enum PlaybackEvent {
  Ready = 'ready',
  Play = 'play',
  Playing = 'playing',
  Paused = 'paused',
  Seeking = 'seeking',
  Seeked = 'seeked',
  Ended = 'ended',
  TimeChanged = 'time-changed',
  StallStarted = 'stall-started',
  StallEnded = 'stall-ended',
  VideoDetached = 'video-detached',
  VideoAttached = 'video-attached',

Some of these are still just mapped from videoElement events and will be moved towards triggering through internal state transitions.

ViewMode api

Some other packages that will extend the SourceApi are for eg the ViewModePackage, which gives us API to control view mode of the source.

enum ViewMode {
  Inline = 0,
  Fullscreen = 1,
  PictureInPicture = 2,

const sourceApi = player.sources.add(sourceConfig);
if (sourceApi.isAvailable(ViewMode.Fullscreen)) {