Quick Access

1. Global Configuration

1.1. playerjs.config

It includes configurations for the s17 server and player settings, effective for all player instances created by H5Player. This configuration must be set before instantiation.

Usage Instruction

playerjs.config = { ...customConfig };

1.1.1. Basic Configuration Items

Name Type Default Value Required Description
baseURL String Yes Custom request prefix. It must include protocol, IP, and port, e.g., https://test-2100.xxxx.com:20551/getway
decoderType Number 2 No The decoding type. 0: wasm, 1: mse, 2: WebCodecs. If the browser doesn't support the specified decoding method, it will automatically downgrade.
operationTimeout Number 60 No The operation timeout duration (in seconds). 1. For playback, it is used to detect if seek times out; 2. The loading timeout duration (in seconds). During both live view and playback, it is used to detect if loading times out.
logLevel Number 6 No Log level, 0-4, from low to high, representing 0-trace, 1-debug, 2-info, 3-warn, 4-error, 5-fatal, 6-off (no logs printed)
hardwareAcceleration Number 0 No Whether to enable hardware decoding for WebCodecs. 0-browser auto-select, 1-hardware decoding, 2-software decoding. Only effective when decoderType = 2. If live view requires higher real-time performance, set this to 2, though it will sacrifice some performance.
fullRatio Number 0 No The threshold value for the stretch ratio when filling the screen - if below this value, the content will not be stretched and will be displayed at its original aspect ratio. Value range: 0-1. (V2.0.3)

1.1.2. AI Mosaic Capability Display

Description

When a video contains mosaic information and needs to be displayed, the AI mosaic capability can be used to obscure certain key visuals, such as faces.

Configuration Items

Name Type Default Value Required Description
mosaic Number 0 No Whether to apply mosaic: 0 - No mosaic, 1 - Plugin mosaic (effective with wasm decoding), and 2 - Front-end mosaic. For high confidentiality, set decoderType to 0 and mosaic to 1.
mosaicType Number 1 No 0: Blur effect; 1: Mosaic

Example

playerjs.config = {
    mosaic: 2, // Front-end mosaic.
    mosaicType: 1 // Mosaic effect, 0: blur, 1: mosaic
};

1.1.3. AI Information Display

Description

ADAS overlay information display: The displayed information includes lane markings, alarm identifiers, vehicle markers, pedestrian markers, current speed, and distance to the vehicle ahead.

DMS overlay information display: The displayed information includes alarm identifiers for driver phone usage, distracted driving, and seat belts not fastened.

AEB information acquisition: It mainly includes forward collision used for OSD overlay.

Bucket information display: It mainly displays the bucket tooth position of the excavator to determine if any bucket teeth are missing.

Configuration Items

Name Type Default Value Required Description
adas Boolean false No It specifies whether to enable the ADAS information display.
dms Boolean false No It specifies whether to enable the alarm DMS information display.
aeb Boolean false No It specifies whether to enable the AEB alarm information.
bucket Boolean false No It specifies whether to enable the bucket information display.
allowAlarms number[] | undefined undefined No List of alarm IDs. After enabling ADAS or DMS, specify which alarm types are allowed to be displayed. If no alarms need to be displayed, pass []. See alarm types below.
langs object[] undefined No Term configuration, see term configuration table
showCurves string[] undefined No List of curves to display. Options: distance (front vehicle distance curve), speed (speed curve), ttc (alarm duration curve). Pass empty array [] to hide all curves
aiUnit object undefined No AI display units. Speed (default km/h), distance (default m). Refer to unit reference table for configuration options

Alarm List

Alarm Type ID Description
0 Driver abnormal alarm
1 Seat belt not fastened alarm
2 Left/right distraction alarm
3 Looking down distraction alarm
4 Phone usage alarm
5 Smoking alarm
6 Yawning alarm
7 Obstruction alarm
8 Fatigue alarm
9 Infrared blocking glasses alarm
10 Forward collision alarm
11 Vehicle too close alarm
12 Lane departure alarm (left)
13 Lane departure alarm (right)

Distance Unit Mapping Table

Key Description
1 Meter (m)
2 Foot (ft)

Speed Unit Mapping Table

Key Description
1 Kilometer per hour (km/h)
2 Mile per hour (mph)

Example

playerjs.config = {
    adas: true,
    dms: true,
    allowAlarms: [8, 10], // Only allow fatigue and collision alarms to be displayed
    langs: [{
    	key: "VEHICLE TOO CLOSE",
    	value: "VEHICLE TOO CLOSE"
    }],
    showCurves: ['distance', 'ttc'],
    aiUnit: {
    	distance: 2, // ft
    	speed: 2, // mph
    }
};

1.1.4 Video Placeholder

Description

The placeholder plugin can provide a custom placeholder image or text during playback when there is no video stream, offering a visual cue in the absence of video.

Configuration Items

Name Type Default Value Required Description
placeholder Boolean No It specifies whether to enable video placeholder mask.

Example

// Enable the placeholder plugin.
playerjs.config = {
    placeholder: true
};
//Obtain a custom placeholder image.
historyplayer.hooks.onVideoPlaceholder.tap('auto play', (status) => {
    console.error('playerStatusToggle', status, status[0]);
    status.forEach(({ status, next }) => {
        const dom = document.createElement('div');
        dom.style.cssText = 'width:100%; height:100%; background-color:red;';
        dom.style.backgroundImage = `url(https://img2.baidu.com/it/u=263214107,966825174&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500)`;
        // Pass the custom placeholder DOM via next to try the placeholder.
        next(dom);
    });
});

1.1.5. Reconnection

Description

When the device experiences an abnormal disconnection due to network fluctuations, this configuration can trigger automatic reconnection.

Only live view is supported.

Configuration Items

Name Type Default Value Required Description
reconnectCount number 3 No Number of disconnection reconnections. The default value is 3. If you want to disable the connection, please pass 0
reconnectTime number 10 No The default reconnection interval is 10 seconds
reconnectAgainCount number 0 No Number of additional reconnection attempts after reconnectCount is exhausted. Default is 0.
reconnectAgainTime number 0 No Interval for additional reconnection attempts in seconds. Default is 0. Used for reconnection after reconnectCount is exhausted.

Example

playerjs.config = {
    reconnectCount: 3,
    reconnectTime: 10,
    reconnectAgainCount: 5,
    reconnectAgainTime: 20
};

1.1.6. Progress Bar Callback

Description

In playback scenarios, the interval and format for progress callbacks can be set.

Configuration Items

Name Type Default Value Required Description
timeHookInterval Number 500 No The frequency at which the playback time callback onTimeChange hook is pushed, in milliseconds, must be at least 40 ms.
timeFormatter String YYYY-MM-DD HH:mm:ss No The time format for the time callback hook.

Example

playerjs.config = {
    timeHookInterval: 200    timeFormatter:‘YYYY-MM-DD HH:mm:ss’
};

1.1.8 Playback Start Buffering

Description

In cases of poor network conditions, users may want to buffer for a period before starting play to ensure smooth play.

Configuration Items

Name Type Default Value Required Description
needStartBuffer Boolean false No It specifies whether to enable first-frame buffering, used for playback of very short evidence or under poor network conditions.
bufferTime Number 0 No The start playback buffer duration (in seconds). After the first frame or channel is stuck and the buffer reaches this value, the buffering ends. When this configuration item is set to 0, this function is disabled, which means that after buffering, the received data will be played immediately.

Example

playerjs.config = {
    needStartBuffer: true    bufferTime:1
};

1.1.9. Seek Reconnection wait interval

Description

GB28181, standard JT1078 and other devices have no absolute RTC time, and need to use the reconnection mode, so the waiting interval between closing and opening can be configured

Configuration Items

Name Type Default Value Required Description
seekRecWaitTime Number 500 No Wait interval, in ms
playerjs.config = {
    seekRecWaitTime: 500
};

1.2. Header Configuration

The playerjs.defaultHeaders configuration item. When the media service requires authentication, this configuration item must be configured. The specific parameters depend on the media service interface.

Usage Instruction

playerjs.defaultHeaders = {
 _token: 'token'
};

Basic Configuration Items

Name Type Default Value Required Description
_tenantId Number 2 No The tenant ID, optional.
_appId Number 1 No The application ID, optional.
_token String No token
_sign String No sign

Custom request headers are also allowed.

2. Version Manager

2.1. Introduction

The H5Player version loader is used for asynchronous loading and quick switching of SDKs, avoiding SDK version conflicts. It is a compressed JS file that can be used as a static resource in the project or stored on a server for loading. Once the version loader is successfully loaded in the project, the videoSDKVM object will be added to the global window. All subsequent loading, switching, etc. of H5Player need to be implemented through this object.

Note: It is recommended to use this manager to load H5Player in internal projects.

2.2. videoSDKVM

Properties

  • baseUrl: It is used to configure the base JS access path for resources that need to be obtained from the server, facilitating shorthand syntax for subsequent loading.
  • build_time: The compilation and packaging time of the version loader.
  • currentVersion: It is used to retrieve the global object of the currently loaded SDK.

Methods

  • use
const loadSDKPromise = videoSDKVM.use([url|version]);
When baseUrl is not configured, the use method requires filling in the static JS resource address in the server-side SDK (The JS static resource address must be the same origin as the project URL).
After configuring baseUrl, you can directly fill in the version number suffix of the SDK stored on the server side.

Loading Timing

It is recommended to preload when entering the video play page.

Example

//Configure baseUrl.
videoSDKVM.baseUrl = 'http://192.168.132.72:23000/V1.3.9/';
// Load the SDK. (The SDK JavaScript file is relatively large so it can be lazy-loaded after the page loads or during the loading process. This can be customized as needed.)
// Loading method 1: If baseUrl is configured, this method can be used.
const loadSDKPromise = videoSDKVM.use('1.3.9.4be8e803f8942cbf37a8') // Just specify the SDK file name. There's no need to worry about the structure of the file name.
// Loading method 2: No restrictions.
const loadSDKPromise = videoSDKVM.use('The SDK version address, e.g., http://192.168.132.72:23000/V1.3.9/1.3.9.4be8e803f8942cbf37a8.js')
// After the user enters the play page, SDK play needs to be initialized in advance according to the functional requirements. It is not recommended to wait until the user clicks play to initialize.
// Instance creation method 1:
loadSDKPromise.then((playerjs)=>{
 // Live view needs to be created.
 const livePlayer = playerjs.createLivePlayer(dom, {...});
})
// Instance creation method 2:
// After the use method is used to load the SDK, the playerjs object will be attached to the global window, allowing you to create an instance through this object.
try {
 const livePlayer = playerjs.createLivePlayer(dom, {...});
} catch (e){
 // You can loop to check if window.playerjs exists, and reload if necessary.
 loopCheckPlayJS();
 // Or directly use
 const playerjs = await loadSDKPromise();
}