top

How to handle error player events?

Published 2014-10-27 | (Compatible with SDK 3.5,4.5,5.0,5.1 and 2012,2013,2014 models)

Proper assignment of callback functions to plugin player native events

The Samsung player throws error events at the following conditions:

AVPlayNetworkDisconnectedError
If network is disconnected
AVPlayUnsupportedVideoFormatError
If the video codec is not supported
AVPlayUnsupportedVideoResolutionError
If the video resolution is not supported
AVPlayUnsupportedVideoFrameRateError
If the video frame rate is not supported
AVPlayCorruptedStreamError
If the video container is corrupt
InvalidValuesError
If the input attributes do not contain valid values
UnknownError
In the case of any other error

Each of these cases should be handled in the application, to avoid unexpected behavior.

Here is the guide how to assign the event listeners:

function playSuccessCB() {
    console.log("playing the video is successfully.");
}

function successCB(avplayObj) {
    avplayObj.init();
    avplayObj.open("media.avi");
    avplayObj.play(
        playSuccessCB,
        function (error) {
            console.error(error.message); // various error occurred here. 
        },
        5
    );
}

function errorCB(error) {
    console.log("Cannot get avplay object : " + error.name);
}

try {
    webapis.avplay.getAVPlay(successCB, errorCB);
} catch (error) {
    console.log(error.name);
}

Note

Other player events, like buffering or end of stream can be handled exactly in the same way. You can find out more about player native events in the API Reference.