To handle errors in Videojs player, you can use the following code:
const errorCodes = ["MEDIA_ERR_CUSTOM", "MEDIA_ERR_ABORTED", "MEDIA_ERR_NETWORK", "MEDIA_ERR_DECODE", "MEDIA_ERR_SRC_NOT_SUPPORTED", "MEDIA_ERR_ENCRYPTED"];
playerInstance.on("error", function() {
sendEvent("playerError", errorCodes[playerInstance.error().code]);
});
This code snippet sets up an event listener for the "error" event in Videojs player. When an error occurs, it calls the sendEvent()
function with the event name "playerError" and the corresponding error code based on playerInstance.error().code
.
To handle ad errors in Videojs player, you can use the following code:
playerInstance.on("adserror", function(e) {
sendEvent("adError", `aderror-${e.data.AdErrorEvent.error.data.errorCode}`);
});
This code snippet sets up an event listener for the "adserror" event in Videojs player. When an ad error occurs, it calls the sendEvent()
function with the event name "adError" and the specific ad error code extracted from e.data.AdErrorEvent.error.data.errorCode
.
Note: The sendEvent()
function is a generic function used to send events and register them in our analytics code. You should replace it with your own implementation or use an appropriate analytics library.