Error mechanism

H5Player uniformly uses the onError hook for error output, and the access party can obtain the errors through this hook for error display, etc.

grammar

  • player.hooks.onError.tap('an error occurred', callback[errorType, subErrorType, description, info]);

Callback Format

Parameters Type Description
errorType String Error type, please refer to subsequent field details for details.
subErrorType String Error details
description String Error description, which is the Chinese meaning of subErrorType
info: Object devId String Device No
code Number Detailed error code. If the above code is SERVER_ERROR, then the code is the s17 media service interface error code
message String error message
deviceInfos Array Device information list, format [devInfo], devInfo: { channel: Number, devId: String }
time String The time the error occurred. Format YYYY-MM-DD HH:mm:ss
level Number Is it the channel level or the entire player level. 1: Player level, 2: Channel level. Generally used for playback.

Code Example

player = playerjs.createLivePlayer({ ...yourConfig });

// v1.1.x version is used like this
player.hooks.onError.tap('error', (errorType, subErrorType, description, info) => {
    // If the business layer wants to give an error prompt, take "device offline" as an example

    // If the project does not need to use internationalization, you can refer to the following processing
    console.error(errorType, ': ', description); // NETWORK_ERROR: The device is offline

    // If the project uses internationalization, such as i18n, you can refer to the following processing
    // Note: You need to add entries of errorType and subErrorType to the project first
    const { NETWORK_ERROR, DEVICE_OFFLINE } = stPlayer.errorCode.sdkErrorCode;
    if (errorType == NETWORK_ERROR && subErrorType == DEVICE_OFFLINE) {
        //i18n needs to add entries
        console.error(i18n('NETWORK_ERROR'), ': ', i18n('H5_SDK_DEVICE_OFFLINE'));
    }

    // If it is a channel level error, please refer to the following processing
    if (info.level === 2) {
        // If the error message requires Chinese prompts, you can replace subErrorType with description
        console.error(`Channel ${info.deviceInfos[0].channel} error occurred: `, subErrorType);
    }
});

Field details

  • errorType (error type)

Mainly divided into 4 categories:

Parameters Description
NETWORK_ERROR Network errors, including errors returned by the network and s17 service
MEDIA_ERROR Media-related errors during playback, such as format errors, decoding issues, etc.
OTHER_ERROR Errors that occur during non-playback processes, such as default errors in required fields
PARAM_ERROR Parameter error, sdk parameter error and s17 parameter error
  • subErrorType (sub-error type)

Quite the former is more detailed

error(SubErrorTypes) describe(Description)
OTHER_ERROR
H5_SDK_HTTPS_REQUIRED The website needs to use the https protocol
H5_SDK_OPERATION_ERROR Operation error
H5_SDK_NO_MICROPHONE_PERMISSION No microphone permission
H5_SDK_WEBSOCKET_ERROR websocket error
NETWORK_ERROR
H5_SDK_INVALID_URL Invalid url
H5_SDK_STREAM_ABORT Device interruption
H5_SDK_SERVER_ERROR Server error (including other errors in the s17 interface except the following four)
H5_SDK_INVALID_DEVICE Invalid device
H5_SDK_DEVICE_IS_OCCUPIED Device occupation
H5_SDK_REQUEST_TIMEOUT Request timeout
H5_SDK_DEVICE_OFFLINE Device offline
H5_SDK_SEEK_FAILED seek failed
MEDIA_ERROR
H5_SDK_UNPACK_EXCEPTION Decapsulation exception
H5_SDK_DECRYPTION Decryption (AES) exception
H5_SDK_DECODING_EXCEPTION Decoding exception
PARAM_ERROR
H5_SDK_PARAM_SDK_ERROR sdk parameter error
H5_SDK_PARAM_S17_ERROR s17 parameter error
  • info (error message)
Parameters Description
code:string s17 service error code
message:string Error message
time:Date The time when the error occurred
level: string error level;
deviceinfos:[] Device information (including devid, channel, etc.)