As a developer, you could be interested in error handling for any of the following reasons:
You want to render human-friendly error messages inside the video player. Reading this error message,
THEOplayer exposes different types of errors, and they can be accessed and intercepted in different ways.
Error handling is available across platforms and SDKs.
Web SDK | Android SDK | iOS SDK | tvOS SDK | Android TV SDK | Chromecast SDK |
---|---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes | Yes |
Developers can programmatically interact with errors in two ways:
Developers can subscribe to events and attach a callback function. This callback function implements the error handling.
This section describes how to use event handlers for the "top-level", "generic", "player" error
event.
This is the error
event which is dispatched through the Player
interface.
This event is fatal and prevents playback.
(There are also error
events, for example the error
event which is dispatched through the Chromecast
interface.
You handle these error
events in the same fashion.)
player.addEventListener("error", function (errorEvent) {
console.log(errorEvent)
})
theoPlayerView.getPlayer().addEventListener(PlayerEventTypes.ERROR, new EventListener<ErrorEvent>() {
@Override
public void handleEvent(ErrorEvent errorEvent) {
System.out.println(errorEvent.getErrorObject());
}
});
let listener = self.theoplayer?.addEventListener(type: PlayerEventTypes.ERROR, listener: { error in print(error.error)})
Developers can query an occurred "generic player error" through the errorObject
property of its related interface.
For example, if the error
event of the top-level Player
interface would be dispatched for the Web SDK,
then you can access the errorObject
property of this interface.
player.addEventListener("error", function (errorEvent) {
// console.log(errorEvent);
console.log(player.errorObject)
})
Note that other types of errors are not available through this approach.
"Which error related events does the player expose" lists which types of errors there are. Note that generally speaking only the "generic error event" is fatal. Other events, like the "Chromecast error event" and the "ad error event", are considered non-fatal because some type of playback can style continue.
"Error codes" lists which error codes are available for the "generic error event".
We encourage developers to use event listeners to handle errors.
You could render your own error messages inside the video player.