Direct video access

1. API interface

1.1. createLivePlayer

describe

Create a pass-through playback instance

Example

  • livePlayer = playerjs.createLivePlayer(dom: domElement, options: Object)

Parameter details

dom:

The div DOM container needs to set the width and height of the style, otherwise the video may collapse or have other style problems.

options:

Field Type Description Default value Is it required
devId string Device unique identifier Yes
channel string Channel number, starting from 1, the value range is 1~32 Yes
streamType string Stream type: MAJOR: main stream; MINOR: sub-stream; MAJOR No
hasEncrypt number AES decryption type: 0 platform decryption; 1 front-end decryption 0 no
mediaProtocol string Media protocol: HTTP_FLV; WS_FLV; New in 1.3.9 initial HTTP_FLV No
quality string Clarity: SMOOTH: Smooth STANDARD: Standard CLARITY: Clear STANDARD No
hasAudio number Whether to carry audio, audio is turned on by default: 0: not carried 1: carried 1 no
optId string Business operation id, which can be used to operate trace records, etc. "" No
expireTime number Address expiration time, default is 20 seconds 20 No
hasTranscode number Whether H265 video transcoding is required, it will be transcoded by default: 0 => no transcoding, 1 => transcoding 0 no
addrType number Address type: 1: External network address; 2: Intranet address; 1 No

1.2. Method

1.2.1. load

describe

The pass-through player gets the playback flv address and loads the video stream

Example

  • livePlayer.load()

1.2.2. destruction

describe

Destroy pass-through player

Example

  • livePlayer.destroy()

1.2.3. getStartTime

describe

Get the start time of pass-through playback and return the client UTC timestamp in ms.

Example

  • livePlayer.getStartTime()

Note: If you want to get the end time, please refer to afterDestory in HOOKS

1.2.4. getDuration

describe

Get the duration of pass-through playback, in ms.

Example

  • livePlayer.getDuration()

1.3. Properties

1.3.1. streamType: string

describe

Get the player stream type | Set the switched stream type

Example

  • Get: livePlayer.streamType
  • Setting: livePlayer.streamType = 'MAJOR'

Set the value range: MAJOR (main code stream), MINOR (sub-code stream)

1.3.2. volume: number

describe

Get the volume of each channel of the player | Set the volume of the player channel

Example

  • Get: livePlayer.volume
  • Setting: livePlayer.volume = 0.5

Set value range: Number, expected channel volume, range 0 - 1

1.3.3. aspectRatio: number

describe

Set player aspect ratio

Example

  • livePlayer.aspectRatio = "full"

Set the value range: String, full: full, origin: original ratio, ratio mode, such as: 16:9, 4:3, 1:1

1.3.4. (readonly) status: string

describe

Get the current playback status of the player

Example

  • Get: livePlayer.status

Get value status includes:

  • INIT player creation completed
  • CANPLAY video is ready to start playing
  • PLAY Playing
  • DESTORY Destroyed

2. Extended function access

Extended functions

3. Access example

<script src="./streamax-player.js"></script>
<script>
     const StPlayer = H5Player;
     StPlayer.config = {
         httpProtocol: 'http',
         ip: '192.168.132.72',
         port: 21250,
     };
     StPlayer.defaultHeaders = {
         _appId: '1',
         _tenantId: '2',
     }
     let livePlayer = null;
     //Open passthrough
     function play() {
         if (livePlayer) return;
         const divDom = document.getElementById('div');
         //Initialize pass-through player
         livePlayer = StPlayer.createLivePlayer(divDom, {
             devId: '03d430b6365943f1b02bdde73aceddf8',
             streamType: 'MAJOR',
             channel: '1'
         });
         livePlayer.load();
         livePlayer.hooks.afterLoaded.tap('loaded', () => {
             livePlayer.play();
         });
     }
     // Close passthrough
     function closeVideo() {
         if (livePlayer) {
             livePlayer.destroy();
             livePlayer = null;
         }
     }
</script>