HOOKS Access

H5Player implements hook functions during the playback process based on webpack/tapable, providing access parties with the feasibility of intervening during the playback process.

1. Interface Summary

Name Trigger Event Callback Parameters
afterPlayerInit Triggered after player initialization is complete (player, playConfig) Player instance, playback configuration parameters
onChannelRender Channel rendering AI parameter callback (param: Frame['param'], renderer: PlayRender) Frame data AI parameters, rendering DOM node
afterLoaded Successfully obtained stream data connection (player, eventData) Player instance, returned connection data
afterReady Playback ready event, used for user-triggered playback (player, eventData) Player instance, returned playback status data
beforePlay User call triggers play (player, eventData) Player instance, delivered playback data
afterPlay Renderer starts playing, state machine changes to playing status (player, eventData) Player instance, delivered playback data
beforePause User call triggers pause (player, eventData) Player instance, delivered playback data
afterPause Renderer pauses playback, state machine changes to paused status (player, eventData) Player instance, callback pause data
beforeStop User call triggers stop (player, eventData) Player instance, delivered playback data
afterStop Renderer stops playback, state machine changes to stopped status (player, eventData) Player instance, callback stop data
beforeSeek User call triggers seek, status is seeking (player, eventData) Player instance, delivered playback data
afterSeek Seek successful, state machine changes to playing status (player, eventData) Player instance, callback seek data
beforeDestroy User call triggers destroy (player, eventData) Player instance, delivered destroy data
afterDestroy User call triggers destroy completion (player, eventData) Player instance, delivered destroy data
onError Error callback event (errorData, player) Standard errorData, player instance
onPlayEnded Automatic playback ended (player) Player instance
onLoading Used for callback of loading percentage and network speed information, common for live view and playback (list, done) Player channel status information, flag indicating whether data loading is complete
loadingTimeout Used to determine buffer timeout (20s). Timeout duration is consistent with seek timeout duration (list)
startReconnect Hook for starting reconnection after disconnection (player, eventData) Player instance, reconnection information
reconnectSuccess Hook for successful reconnection after disconnection (player, eventData) Player instance, reconnection information
onVideoPlaceholder Playback channel playback status change. Needs to be distinguished from player status. Playback status refers to whether the channel has stream playback status or no stream idle status during playback; can be used with placeholder plugin to implement custom no-video mask (statusList)
onTimeChange Actively pushes time during playback. Push frequency can be configured in config, default 500ms. If business layer needs smooth timeline movement, frequency can be set lower, especially for small files in server playback (params: [data]) Time information
onMediaInfo Media information callback, currently mainly includes timeList (business layer needs to perceive duration information under network stream conditions) (player, eventData) Player instance, media information
onMessage Prompt information callback event (code, message) Prompt information
onFramePlayNoData Frame-by-frame no data event (player, type) Player instance, frame type (0: next frame, 1: previous frame)
onStreamTypeChange Stream switching event (player, eventData) Player instance, event information
onInputAudioDevicesChange Audio input device change event (eventData, player) Event information, intercom instance
onVolumeChange Volume change event (player, volume) - Player instance, volume data

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

User call triggers seek, status is seeking, only effective for playback.

Example

  • player.hooks.beforeSeek.tap('before seek', callback(player, eventData));

Callback Parameters

Parameter Type Description
player Player instance Player instance
eventData Delivered playback data Delivered playback data

2.11. afterSeek

Description

Completed progress jump seek trigger, only effective for playback.

Example

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

Callback Parameters

Parameter Type Description
timeData Object Time data, refer to afterStop
player Player instance Player instance

Note: In seek failure scenarios, onError callback is used

2.12. beforeDestroy

Description

Callback before video destruction.

Example

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

Callback Parameters

Parameter Description
player Player instance
eventData Callback data

2.13. onPlayEnded

Description

Playback completion

Example

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

2.14. onError

Description

Error callback, can listen to various errors generated in playback and live view

Example

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

Callback Parameters

Parameter Type Description
errorInfo Object Other information
player class Player instance

For details, refer to error-code.md

2.15. startReconnect

Description

Hook for starting reconnection after live view disconnection.

Example

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

2.16. reconnectSuccess

Description

Hook for successful reconnection after live view disconnection.

Example

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

2.17. onVideoPlaceholder

Description

Playback channel playback status change. Needs to be distinguished from player status. Playback status refers to whether the channel has stream playback status or no stream idle status during playback; can be used with placeholder plugin to implement custom no-video mask

Example

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

Callback Parameters

Parameter Data Type Description
playersStatus Object[] Collection of channel playback status changes
playerStatus:Object devId String Device ID
channel Number Channel number
status String Changed playback status
next Function Callback function requiring 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, options))

Callback Parameters

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

options

Parameter Description
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 Data Type Description
player class Player instance
stateInfo object Refer to stateInfo type definition below
state string Refer to Player Status

stateInfo

type TStateInfo = {
    [key: string]: {
        state: string, // Refer to player status
        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 definition below

TEventData

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

2.27. onInputAudioDevicesChange

Description

Player stream switching callback

Example

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

Callback Parameters

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

TEventData

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

2.28. afterDestroy

Description

Player destruction completion callback

Example

  • player.hooks.afterDestroy.tap('after destroy', callback(player, eventData))

Callback Parameters

Parameter Data Type Description
player class Player instance
eventData object Callback data

2.29. onVolumeChange

Description
Volume change callback

Example

player.hooks.onVolumeChange.tap('volume change', callback(player, volume))

Callback Parameters

Parameter Type Description
player class Player instance
volume IVolume[] Callback data

IVolume Type Definition

interface IVolume {
    devId: string;    // Device ID  
    channel: number;  // Channel  
    volume: number;   // Volume level  
}