H5Player implements hook functions during the playback process based on webpack/tapable, providing access parties with the feasibility of intervening during the playback process.
| 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 |
Description
It is triggered after the player is initialized, and is currently only effective for live view instances.
Example
Note: The player in the example refers to the player instance.
Callback Parameters
| Parameter | Description |
|---|---|
| player | The player instance |
| config | The parameters for rendering |
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
Callback Parameters
| Parameter | Description |
|---|---|
| player | The player instance |
| eventData | The returned link data |
Description
It is triggered when the player is ready to start playing, applicable to both live view and playback.
Example
Callback Parameters
| Parameter | Description |
|---|---|
| player | The player instance |
| eventData | The returned play status data |
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
Callback Parameters
| Parameter | Description |
|---|---|
| player | The player instance |
| eventData | The play data delivered |
Description
It is triggered after the player receives the play notification, effective for playback.
Example
Callback Parameters
| Parameter | Description |
|---|---|
| player | The player instance |
| eventData | The play data delivered |
Description
It is triggered before the player receives the pause notification, effective for playback.
Example
Callback Parameters
| Parameter | Description |
|---|---|
| player | The player instance |
| eventData | The play data delivered |
Description
It is triggered after the player receives the pause notification, effective for playback.
Example
Callback Parameters
| Parameter | Description |
|---|---|
| player | The player instance |
| eventData | The play data delivered |
Description
Callback before the video stops, effective for playback.
Example
Callback Parameters
| Parameter | Description |
|---|---|
| player | The player instance |
| eventData | The play data delivered |
Description
It is triggered after the player stops.
Example
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. |
Description
User call triggers seek, status is seeking, only effective for playback.
Example
Callback Parameters
| Parameter | Type | Description |
|---|---|---|
| player | Player instance | Player instance |
| eventData | Delivered playback data | Delivered playback data |
Description
Completed progress jump seek trigger, only effective for playback.
Example
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
Description
Callback before video destruction.
Example
Callback Parameters
| Parameter | Description |
|---|---|
| player | Player instance |
| eventData | Callback data |
Description
Playback completion
Example
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
Description
Hook for starting reconnection after live view disconnection.
Example
Description
Hook for successful reconnection after live view disconnection.
Example
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
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 |
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
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. |
Description
Used to determine the buffer timeout. The timeout duration follows the general configuration, with a default of 20s.
Example
Callback Parameters
| Parameter | Data Type | Description | |
|---|---|---|---|
| deviceInfo | Object[] | The list of device channels | |
| deviceInfo:Object | devId | String | Device ID |
| channel | Number | Channel number |
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
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. |
Description
It provides the device information or AI information of the currently rendered frame in the player.
Example
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. |
Description
Media information feedback
Example
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 |
Description
Prompt information callback
Example
Callback Parameters
| Parameter | Data Type | Description |
|---|---|---|
| code | string | Prompt error code |
| message | string | Prompt description |
Description
Frame-by-frame no data callback
Example
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 |
Description
Player state change callback
Example
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
Description
Player stream switching callback
Example
Callback Parameters
| Parameter | Data Type | Description |
|---|---|---|
| player | class | Player instance |
| eventData | object | Refer to TEventData type definition below |
TEventData
Description
Player stream switching callback
Example
Callback Parameters
| Parameter | Data Type | Description |
|---|---|---|
| eventData | object | Refer to TEventData type definition below |
| player | class | Player instance |
TEventData
Description
Player destruction completion callback
Example
Callback Parameters
| Parameter | Data Type | Description |
|---|---|---|
| player | class | Player instance |
| eventData | object | Callback data |
Description
Volume change callback
Example
Callback Parameters
| Parameter | Type | Description |
|---|---|---|
| player | class | Player instance |
| volume | IVolume[] | Callback data |
IVolume Type Definition