Handling Errors for an HTML5 Player V3 Using JavaScript (Deprecated)

Error Handling functions and events enable you to get information about Player V3

Note: Ooyala Player V3 has been deprecated and is scheduled to be disabled. For details and alternatives, see the OVP Release Notes.

Player V3 error functions and events are described in the following tables.

Error Functions

The following table describes the supported error handling functions.

Function Description
getError, getErrorCode Displays the video error code. Note that getErrorText() is not available or supported.
getState Retrieves the current player state. Possible states are defined in OO.STATE as follows
  • LOADING
  • READY
  • PLAYING
  • PAUSED
  • BUFFERING
  • ERROR
  • DESTROYED

Player V3 Error Messages

The following namespaces, described in the Player JavaScript API Reference, contain the error messages that can be handled through the V3 JavaScript Message bus. Use message bus events to handle errors by subscribing to or intercepting the OO.EVENTS.ERROR event:

Error Namespace Description
OO.ERROR Represents the Ooyala V3 Player Errors. This is the parent namespace for all errors, and includes errors for channel content.
OO.ERROR.API Represents errors related to content, metadata, and server connection.
OO.ERROR.API.SAS Represents all authorization-related errors.
OO.ERROR.PLAYBACK Represents all errors related to playback.

Player V3 Error Events

The following table describes the error handling events published by the message bus.

Error Event Description
PLAYER_CREATED The very first message that is published after player is created, used to notify all plugins to initialize themselves.
ERROR Published when error has occurred, second parameter has error details.
DESTROY Published when player is being destroyed.

Working With the Error Event

The OO.EVENTS.ERROR event is published to the message bus. Here's how you can work with it.
You have two design options for how you handle the error:
  • mb.subscribe triggers the function you specify (the callback function) when an error happens, and the error continues to propagate to other subscribers.
  • mb.intercept hijacks the error notification and allows you to modify the payload for future subscribers. That is, intercepting errors allows you to change error messages if you really want to.
Perhaps the most practical recommendation is to use mb.subscribe and handle the error as desired according to any existing error-handling functions you might already have in place(such as print it out to console, stop playback, throw up an error screen, etc).
In the following example illustrating the use of the Message Bus subscribe() method, the callback function YourErrorHandlingFunctionNameHere is invoked if the OO.EVENTS.ERROR event is published to the message bus:
        <div id="ooyalaplayer" style="width:640px;height:360px"></div>
        <script>
          function onCreate(player) {
          
            player.mb.subscribe(
              OO.EVENTS.ERROR, 
              'test', 
              function(event, payload) {  
                YourErrorHandlingFunctionNameHere(yourArgs); 
              }
            );
          }
            
          OO.ready(function() { 
            player = OO.Player.create(
              'ooyalaplayer', 
              'hkbTd2czrIYRs4-HnJ9nVcHSxtA07FUK', {
                onCreate : window.onCreate
              }
            );        
        </script>
In the following example illustrating the use of the Message Bus intercept() method, when an error occurs, the message "Houston, we have a problem." is printed to the JavaScript console.

//Intercept error
player.mb.intercept(OO.EVENTS.ERROR, "test-plugin", function(eventName, payload) { return ["Houston, we have a problem."]; });
   

For complete examples that include the use of Message Bus events, see Advanced JavaScript Examples for Player V3 (Deprecated).

Was this article helpful?