Skip to main content

Player Interface

The PlayerInterface in Elevate Web acts like the common functionality contract for player implementations to make them easier to integrate into the application so that all implementations can be referenced by the generic interface.

Key Notes

  • Generic parameters
    • TPlayerLibrary generic parameter refers to the type of the underlying player object being used.
  • The optional methods addEventListener and removeEventListener wrap the underlaying methods for the video element.
  • The optional methods listen and unlisten wrap the custom event listener methods that a player library may provide.
  • Use init method to initialize any internal objects or data structures. This method is required to be called before using the other methods such as load or play.
  • Use dispose method to release any object and free references. If you want to use the player again you need to reinitialize the player calling init.
  • The getName function can be used to safely identify which player implementation is being used at runtime. Each player class should use a different identifier to allow this safe validation.

Extending Generic Parameters

Some functions in the interface such as load use a generic parameter to define its properties. This is helpful to extend the required data needed for a specific implementation however there is a caveat. You cannot extend the values with required properties. This is by design in Typescript as an extended implementation can be referred as the interface it implements which have no information of the new required fields. The valid alternatives are:

  • Add a new optional property and add the required validation in the implementation to prevent null or undefined values.
  • Update the player interface PlayerInterface to include the required properties. However this approach has the downside that all players will need to implement the new property. So this option needs to be consider carefully.