HOOKS Access

The H5Player implements hook functions during playing based on webpack/tapable. This provides the access party with the feasibility of intervening during playing.

1. Interface Summary

Name Trigger Event Callback Parameters
afterPlayerInit Triggered after player initialization. (player, playConfig) The player instance and the play configuration parameters
onChannelRender Triggered by AI parameter callback for channel rendering. (param: Frame['param'], renderer: PlayRender) The frame data AI parameters, rendering DOM node
afterLoaded Triggered when the stream data connection is successfully acquired. (player, eventData) The player instance and the returned link data
afterReady Triggered by the play-ready event for user-triggered play. (player, eventData) The player instance and the returned play status data
beforePlay Triggered when the user calls to play. (player, eventData) The player instance and the play data delivered
afterPlay Triggered when the renderer begins to play, and the state machine changes to Playing status. (player, eventData) The player instance and the play data delivered
beforePause Triggered when the user calls to pause. (player, eventData) The player instance and the play data delivered
afterPause Triggered when the renderer pauses playing, and the state machine changes to Paused status. (player, eventData) The player instance and the callback pause data
beforeStop Triggered when the user calls to stop. (player, eventData) The player instance and the play data delivered
afterStop Triggered when the renderer stops playing, and the state machine changes to Stopped status. (player, eventData) The player instance and the callback stop data
beforeSeek Triggered when the user calls to seek, entering Seeking status. (player, eventData) The player instance and the play data delivered
afterSeek Triggered when the seek is successful, and the state machine changes to Playing status. (player, eventData) The player instance and the callback seek data
beforeDestroy Triggered when the user calls to destroy. (player, eventData) The player instance and the destroy data delivered
onError Error callback event (errorData, player) The standard errorData and the player instance
onPlayEnded Triggered when the auto-play ends. (player, eventData) The player instance and the ended channel information data
onLoading Used for callback of loading percentage and network speed information, applicable to both live view and playback. (list, done) The player channel status information and the flag indicating whether loading is complete
loadingTimeout Used to determine the buffer timeout (20 s). The timeout duration is the same as the seek timeout. (list)
startReconnect The hook triggered when starting to reconnect after a disconnection. (player, eventData) The player instance and the reconnection information
reconnectSuccess The hook triggered upon successful reconnection after a disconnection. (player, eventData) The player instance and the reconnection information
onVideoPlaceholder Triggered when the playback channel status changes. It needs to be distinguished from the player status. The playback status refers to whether the channel is playing a stream or is idle. The placeholder plugin can be used to customize the mask when there is no video. (statusList)
onTimeChange Actively pushes time during playback. The push frequency can be configured in config. The default value is 500ms. For smooth timeline movement in the business layer, the frequency can be set lower, especially for small files in server playback. (params: [data]) The time information
onMediaInfo Media information callback, currently mainly including timeList (business layer needs to perceive duration information under network flow conditions) (player, eventData) The player instance and media info
onMessage Prompt information callback event (code, message) Reminder information
onFramePlayNoData Frame-by-frame no data event (player, type) The player instance and frame type (0: next frame, 1: previous frame)
onStreamTypeChange Stream switching event (player, eventData) Player instance, event data
onInputAudioDevicesChange Audio input device change event (eventData, player) Event data, intercom instance

2. APIs

2.1. afterPlayerInit

Description

It is triggered after the player is initialized, and is currently only effective for live view instances.

Example

  • player.hooks.afterPlayerInit.tap('after init', callback(player, config));

Note: The player in the example refers to the player instance.

Callback Parameters

Parameter Description
player The player instance
config The parameters for rendering

2.2. afterLoaded

Description

It is triggered after the player obtains the media stream address. At this point, the video has not started playing nor has the intercom been listened. It is effective for live-view players, playback players, and intercom listening instances.

Example

  • player.hooks.afterLoaded.tap('afterLoaded', callback(player, eventData));

Callback Parameters

Parameter Description
player The player instance
eventData The returned link data

2.3. afterReady

Description

It is triggered when the player is ready to start playing, applicable to both live view and playback.

Example

  • player.hooks.afterReady.tap('afterReady', callback(player, eventData));

Callback Parameters

Parameter Description
player The player instance
eventData The returned play status data

2.4. beforePlay

Description

It is triggered before the player receives the play notification. For live view, the play starts automatically when the load is called, so it only takes effect for playback.

Example

  • player.hooks.beforePlay.tap('beforePlay', callback(player, eventData));

Callback Parameters

Parameter Description
player The player instance
eventData The play data delivered

2.5. afterPlay

Description

It is triggered after the player receives the play notification, effective for playback.

Example

  • player.hooks.afterPlay.tap('afterPlay', callback(player, eventData));

Callback Parameters

Parameter Description
player The player instance
eventData The play data delivered

2.6. beforePause

Description

It is triggered before the player receives the pause notification, effective for playback.

Example

  • player.hooks.beforePause.tap('beforePause', callback(player, eventData));

Callback Parameters

Parameter Description
player The player instance
eventData The play data delivered

2.7. afterPause

Description

It is triggered after the player receives the pause notification, effective for playback.

Example

  • player.hooks.afterPause.tap('afterPause', callback(player, eventData));

Callback Parameters

Parameter Description
player The player instance
eventData The play data delivered

2.8. beforeStop

Description

Callback before the video stops, effective for playback.

Example

  • player.hooks.beforeStop.tap('beforeStop', callback(player, eventData));

Callback Parameters

Parameter Description
player The player instance
eventData The play data delivered

2.9. afterStop

Description

It is triggered after the player stops.

Example

  • player.hooks.afterStop.tap('after stop', callback[player, timeData]);

Callback Parameters

The timeData parameter is of Object type and is only applicable for intercom listening. The structure is as follows:

Parameter Description
startTime The start time, client UTC timestamp (in milliseconds). If not started, this value is null.
endTime The end time, client UTC timestamp (in milliseconds).
duration The play duration (in milliseconds). If not started, this value is null.

2.10. beforeSeek

Description

It is triggered when the user calls to seek, entering a Seeking status. This is only effective for playback.

Example

  • player.hooks.afterSeek.tap('after seek', callback(player, eventData));

Callback Parameters

Parameter Type Description
player The player instance
eventData The play data delivered

2.11. afterSeek

Description

It is triggered after the seek operation is completed. This is only effective for playback.

Example

  • player.hooks.afterSeek.tap('after seek', callback(timeData));

Callback Parameters

Parameter Type Description
timeData Object The time data. Refer to afterStop.

Note: In case of a seek failure, the onError callback will be used.

2.12. beforeDestroy

Description

Callback before the video is destroyed.

Example

  • player.hooks.beforeDestroy.tap('beforeDestroy', callback(player, preventExecution));

Callback Parameters

Parameter Description
player The player instance
preventExecution A blocking function to prevent further execution of destroy

2.13. onPlayEnded

Description

It is triggered when playback is completed.

Example

  • player.hooks.onPlayEnded.tap('onPlayEnded', callback(player));

2.14. onError

Description

The error callback that listens to various errors occurring during playback or live view.

Example

player.hooks.onError.tap('An error occurred', callback(errorInfo, player?));

Callback Parameters

Name Type Description
errorInfo Object Additional information
player class The player instance

For details, refer to error-info

2.15. startReconnect

Description

The hook triggered when starting to reconnect after a disconnection in live view.

Example

  • player.hooks.startReconnect.tap('start reconnecting', callback(player));

2.16. reconnectSuccess

Description

The hook triggered upon successful reconnection after a disconnection in live view.

Example

  • player.hooks.reconnectSuccess.tap('reconnectSuccess', callback(player));

2.17. onVideoPlaceholder

Description

Triggered when the playback channel status changes. It needs to be distinguished from the player status. The playback status refers to whether the channel is playing a stream or is idle. The placeholder plugin can be used to customize the mask when there is no video.

Example

  • player.hooks.onVideoPlaceholder.tap('placeholder', callback(playersStatus));

Callback Parameters

Parameter Data Type Description
playersStatus Object[] The collection of channel play status changes
playerStatus:Object devId String Device ID
channel Number Channel number
status String The changed play status
next Function The callback function for placeholder

2.18. onLoading

Description

Used for callback of loading percentage and network speed information, applicable to both live view and playback.

Note: In live view mode, you cannot use the done parameter to determine if loading is finished. You need to check if the channel's percent equals 100 to cancel loading for a single channel.

Example

  • player.hooks.onLoading.tap('on loading', callback(loadingList, done));

Callback Parameters

Parameter Data Type Description
loadingList Object[] List of device channel information during loading
devId string Device number
channel number Channel number
percent number The loading progress percentage, which is ranging from 0 to 100.
network number The network speed information (in KB/s).
done boolean Indicates whether the loading is completed.

2.19. loadingTimeout

Description

Used to determine the buffer timeout. The timeout duration follows the general configuration, with a default of 20s.

Example

  • player.hooks.loadingTimeout.tap('loading timeout', callback(deviceInfos));

Callback Parameters

Parameter Data Type Description
deviceInfo Object[] The list of device channels
deviceInfo:Object devId String Device ID
channel Number Channel number

2.20. onTimeChange

Description

Actively pushes time during playback. The push frequency can be configured in config. The default value is 500ms.

For smooth timeline movement in the business layer, the frequency can be set lower, especially for small files in server playback.

Example

  • player.hooks.onTimeChange.tap('time change', callback(timeData));

Callback Parameters

Parameter Data Type Description
timeData Object
dateTime String The formatted time string according to the provided timezone configuration, e.g., "2022-12-28 16:17:34". The format can be configured in the global configuration Config. The default value is "YYYY-MM-DD HH:mm:ss".
utc Number The UTC time in seconds (int).
ms Number The milliseconds after UTC seconds, which is ranging from 0 to 999.

2.21. onChannelRender

Description

It provides the device information or AI information of the currently rendered frame in the player.

Example

  • player.hooks.onChannelRender.tap('onChannelRender', callback(frame, chanPlayer))

Callback Parameters

Parameter Data Type Description
frame object The frame data carrying AI or device information.
chanPlayers object The channel player currently rendering the frame.

2.22. onMediaInfo

Description

Media information feedback

Example

  • player.hooks.onMediaInfo.tap('onMediaInfo', callback(player, eventData))

Callback Parameters

Parameter Data Type Description
player class Player instance
eventData object The channel player currently rendering the data frame
|-name string Data type name: such as timeList
|-data object Data type information

2.23. onMessage

Description

Prompt information callback

Example

  • player.hooks.onMessage.tap('onMessage', callback(code, message))

Callback Parameters

Parameter Data Type Description
code string Prompt error code
message string Prompt description

2.24. onFramePlayNoData

Description

Frame-by-frame no data callback

Example

  • player.hooks.onFramePlayNoData.tap('frame play no data', callback(player, type))

Callback Parameters

Parameter Data Type Description
player class The player instance
type number Frame type. 0-next frame, 1-previous frame
options object Other parameters. Refer to the following table

options

参数 说明
isFirst Whether it's the first frame
isLast Whether it's the last frame

2.25. onStateChange

Description
Player state change callback

Example

  • player.hooks.onStateChange.tap('state change', callback(player, stateInfo, state))

Callback Parameters

Parameter Type Description
player class Player instance
stateInfo object Refer to the stateInfo type definition below
state string Refer to Player States

stateInfo

type TStateInfo = {
    [key: string]: {
        state: string, // Refer to player states
        info: {
            oneDev: {
                devId: string, // Device ID
                channel: string, // Channel number
            },
            devId: string, // Device ID
            channel: string, // Channel number
        }
    }
}

2.26. onStreamTypeChange

Description

Player stream switching callback

Example

  • player.hooks.onStreamTypeChange.tap('stream change', callback(player, eventData))

Callback Parameters

Parameter Data Type Description
player class Player instance
eventData object Refer to TEventData type below

TEventData

type TEventData = {
    devId: string, // Device ID
    channel: number, // Channel number
    streamType: 'MAJOR' | 'MINOR', // Stream type
}

2.27. onInputAudioDevicesChange

Description

Player audio input devices change callback

Example

  • player.hooks.onInputAudioDevicesChange.tap('device change', callback(eventData, player))

Callback Parameters

Parameter Data Type Description
eventData object Refer to TEventData type below
player class Player instance

TEventData

type TEventData = {
    audioDevicesInput: MediaDeviceInfo[], // Input devices information
    audioDevicesOutput: MediaDeviceInfo[], // Output devices information
    deviceInputIdUse: string | undefined, // Currently used input device ID
}