H5Player implements the hook function of the playback process based on webpack/tapable, providing the access party with the feasibility of intervention in the playback process.
Note: The hooks currently provided are all synchronous
hooks name | callback definition | description |
---|---|---|
afterPlayerInit | SyncHook([player, renderConfig]) | Triggered after the player is initialized. Currently only effective for pass-through instances. |
afterRendererInit | SyncHook([renderer, decoder]) | Rendering, decoder initialization completed |
afterControl | SyncHook([object]) | Decoder operation result callback, pass-through takes effect |
afterLoaded | SyncHook([player]) | Triggered after the player obtains the media stream address. At this time, it does not start playing the video or monitoring the intercom. It is effective for pass-through players, playback players, and monitoring intercom instances. |
afterReady | SyncHook([player]) | The player is ready to start playing, supporting pass-through and playback. |
afterBufferChange | SyncHook([object]) | Player cache amount changes, only used by plug-ins |
onAcceptFrameData | SyncHook([decoder, param]) | Receive video frame alarm information, often used in SDK plug-in development |
beforePlay | SyncHook([player, preventExecution]) | Triggered before the player plays the notification (play). Passthrough will automatically play when calling load, so only playback takes effect |
beginPlay | SyncHook([]) | Start playing; currently pass-through is in effect |
afterPlay | SyncHook([player]) | Triggered after the player gets the play notification (play), and the playback takes effect. |
beforePause | SyncHook([player, preventExecution]) | Triggered before the player gets the pause notification (pause), playback takes effect. |
afterPause | SyncHook([player]) | Triggered after the player gets the pause notification (pause), and playback takes effect. |
afterSeek | SyncHook([timeData]) | After the player sets the time currentTime, it is triggered after the progress jump seek is completed. Only playback takes effect. |
beforeStop | SyncHook([player, preventExecution]) | Callback before the video stops, playback takes effect. |
afterStop | SyncHook([player, timeData]) | Triggered after the player stops. |
beforeDestory | SyncHook([player, preventExecution]) | Callback before the video is destroyed. |
afterDestory | SyncHook([player, timeData]) | Callback after destruction |
onPlayEnded | SyncHook([player]) | Playback completed |
onError | SyncHook([ErrorType, SubErrorType, ErrorDescription, ErrorInfo]) | Error callback, can monitor various errors generated during playback and passthrough |
startReconnect | SyncHook([player]) | A hook that starts reconnecting after the direct connection is disconnected. |
reconnectSuccess | SyncHook([player]) | Hook for successful reconnection after direct disconnection. |
afterListenTalkAutoClose | SyncHook([player]) | Triggered after the device actively disconnects when listening to intercom. Only used to monitor intercom. |
playerStatusToggle | SyncHook([playersStatus]) | Change the playback status of the playback channel. It needs to be distinguished from the player state. The playback state refers to whether the channel is in the playback state with streaming or in the idle state without streaming during the playback process. It can be used with the placeholder plug-in to implement custom masking when there is no video |
startLoading | SyncHook([deviceInfo]) | Used to determine whether there is currently a channel to start buffering, usually used when the network is poor |
stopLoading | SyncHook([deviceInfo]) | Used to determine whether the current channel has ended buffering and can start playback. Usually used when the network is poor. |
onLoading | SyncHook([loadingList, done]) | Used to call back the percentage information and network speed information during loading, common for passthrough and playback. |
loadingTimeout | SyncHook([deviceInfo]) | Used to determine buffer timeout (20s). In 1.3.9, the timeout duration remains the same as the seek timeout duration. |
onTimeChange | SyncHook([timeData]) | Actively push the time during playback. The push frequency can be configured in config, and the default is 500ms. If the business layer requires smooth movement of the timeline, the frequency can be set lower, especially for small files played back by the server. |
onChannelRender | SyncHook([frame, chanPlayer]) | Gives the device information or AI information of the current player rendering frame |
describe
Triggered after the player is initialized. Currently only effective for pass-through instances.
Example
Note: player is the playback instance
Callback Parameters
Parameters | Description |
---|---|
player | player instance |
config | rendering parameters |
describe
Rendering, decoder initialization completed
Example
Callback Parameters
Parameters | Description |
---|---|
renderer | renderer |
decoder | decoder |
describe
Decoder operation result callback, pass-through takes effect
Example
Callback Parameters
Parameters | Description |
---|---|
type | Player operation type |
status | Operation status, 0: failure; 1: success |
utc | video timestamp |
describe
It is triggered after the player obtains the media stream address. At this time, it does not start playing the video or monitoring the intercom. It is effective for pass-through players, playback players, and monitoring intercom instances.
Example
Callback Parameters
Parameters | Description |
---|---|
player | player instance |
describe
The player is ready to start playing and supports pass-through and playback.
Example
Callback Parameters
Parameters | Description |
---|---|
player | player instance |
describe
The amount of player cache has changed and is only used by plug-ins.
Example
Callback Parameters
Parameters | Description |
---|---|
startTime | Buffering start time |
endTime | buffer end time |
frameCount | Number of buffered video frames |
session | session |
describe
Receive video frame alarm information, often used in SDK plug-in development
Example
Callback Parameters
Parameters | Description |
---|---|
decoder | decoder |
param | Video alarm parameters |
describe
Triggered before the player plays the notification (play). Passthrough will automatically play when load is called, so only playback takes effect.
Example
Callback Parameters
Parameters | Description |
---|---|
player | player instance |
preventExecution | function, blocking function, can be used to prevent subsequent execution of play |
describe
Start playing; currently pass-through is in effect
Example
describe
Triggered after the player gets the play notification (play), playback takes effect.
Example
Callback Parameters
Parameters | Description |
---|---|
player | player instance |
describe
Triggered before the player gets the pause notification (pause), playback takes effect.
Example
Callback Parameters
Parameters | Description |
---|---|
player | player instance |
preventExecution | function, blocking function, can be used to prevent subsequent execution of pause |
describe
Triggered after the player gets the pause notification (pause), playback takes effect.
Example
Callback Parameters
Parameters | Description |
---|---|
player | player instance |
describe
After the player sets the time currentTime, it is triggered after the progress jump seek is completed, and only playback takes effect.
Example
Callback Parameters
Parameters | Type | Description |
---|---|---|
timeData | Object | Time data, refer to afterStop. |
Note: The onError callback is used in the scenario where seek fails.
describe
Called back before the video stops and playback takes effect.
Example
Callback Parameters
Parameters | Description |
---|---|
player | player instance |
preventExecution | function, blocking function, can be used to prevent subsequent execution of stop |
describe
Fired after the player has stopped.
Example
Callback Parameters
The timeData type is Object. This parameter is only available for monitoring intercoms. The structure is as follows:
Parameters | Description |
---|---|
startTime | Start time, client UTC timestamp, unit: milliseconds. If not started, the value is null. |
endTime | End time, client UTC timestamp, unit: milliseconds. |
duration | Playback duration, unit: milliseconds. If not started, the value is null. |
describe
Callback before the video is destroyed.
Example
Callback Parameters
Parameters | Description |
---|---|
player | player instance |
preventExecution | function, blocking function, can be used to prevent subsequent execution of destroy |
describe
Callback after destruction
Example
Callback Parameters
The timeData type is Object. This parameter is only available for passthrough. Please refer to afterStop.
Parameters | Description |
---|---|
player | player instance |
timeData | Reference afterStop |
describe
Playback completed
Example
describe
Error callback, can monitor playback and various errors generated during pass-through
Example
player.hooks.onError.tap('An error occurred', callback(errorType, subErrorType, errorDesription, errorInfo));
Callback Parameters
Parameter name | Type | Description |
---|---|---|
errorType | String | Error type |
subErrorType | String | Error subtype |
errorDescription | String | Error description |
errorInfo | Object | Rest of information |
For details, refer to error-code.md
describe
After the direct connection is disconnected, the hook starts reconnection.
Example
describe
After the direct connection is disconnected, the hook is successfully reconnected.
Example
describe
When monitoring intercom, it is triggered after the device actively disconnects. Only used to monitor intercom.
Example
Callback Parameters
Parameters | Description |
---|---|
player | Monitoring or intercom instance |
describe
The playback status of the playback channel changes. It needs to be distinguished from the player state. The playback state refers to whether the channel is in the playback state with streaming or in the idle state without streaming during the playback process. It can be used with the placeholder plug-in to implement custom masking when there is no video.
Example
Callback Parameters
Parameters | Data type | Description | |
---|---|---|---|
playersStatus | Object[] | A 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 that requires placeholder |
describe
Used to determine whether there is currently a channel starting to buffer, usually used when the network is poor.
Example
Callback Parameters
Parameters | Data type | Description | |
---|---|---|---|
deviceInfo | Object[] | Device channel list | |
deviceInfo:Object | devId | String | Device Id |
channel | Number | channel number |
describe
Used to determine whether there is currently a channel that has ended buffering and can start playback. Usually used when the network is poor.
Example
Callback Parameters
Parameters | Data type | Description | |
---|---|---|---|
deviceInfo | Object[] | Device channel list | |
deviceInfo:Object | devId | String | Device Id |
channel | Number | channel number |
describe
Used to call back the percentage information and network speed information during loading, common to passthrough and playback.
Example
Callback Parameters
Parameters | Data type | Description | |
---|---|---|---|
loadingList | Object[] | Device channel information list in loading | |
devId | string | device number | |
channel | number | channel number | |
percent | number | Progress percentage, 0-100 | |
network | number | Network speed information, unit KB/s | |
done | boolean | Whether the loading is completed or not loading |
describe
Used to determine buffer timeout (20s). In 1.3.9, the timeout duration remains the same as the seek timeout duration.
Example
Callback Parameters
Parameters | Data type | Description | |
---|---|---|---|
deviceInfo | Object[] | Device channel list | |
deviceInfo:Object | devId | String | Device Id |
channel | Number | channel number |
describe
Actively push the time during playback. The push frequency can be configured in config, and the default is 500ms.
If the business layer requires smooth movement of the timeline, the frequency can be set lower, especially for small files played back by the server.
Example
Callback Parameters
Parameters | Data type | Description | |
---|---|---|---|
timeData | Object | ||
dateTime | String | A time string formatted according to the time zone of the incoming configuration, such as "2022-12-28 16:17:34". This format can be configured in the global configuration config, the default is "YYYY-MM-DD HH:mm:ss" | |
utc | Number | utc time, unit second, int. | |
ms | Number | The number of milliseconds after utc second, value 0-999. |
describe
Gives the device information or AI information of the current player rendering frame
Example
Callback Parameters
Parameters | Data type | Description |
---|---|---|
frame | object | Frame data carrying AI or device information |
chanPlayers | object | The channel player currently rendering this data frame |