With the popularity of Apicloud, more and more users are frustrated that apicloud does not have a truly reliable low latency RTMP/RTSP live player.

In view of this, Daniu Live SDK and apicloud senior moderators launch the Apicloud connection scheme:

Related interfaces are as follows:

DaniuPlayer module overview

This module encapsulates daniu live SDK, which supports RTSP and RTMP playback (developers should control the playback format by themselves), supports second on mode, and supports fast switching video playback address, etc.

For details about the precautions for packing License files, seeLicense module package Precautions

Module interface

addPlayerListener

Player monitoring

addPlayerListener(callback(ret))

callback(ret)

Ret:

  • Type: JSON object
  • Internal fields:
Param1: ",// Param2: ",// Param3: ",// parameter 3 param4: ",// Parameter 4}Copy the code

The sample code

var demo = api.require('daniuPlayer');
demo.addPlayerListener(function(ret){
    api.toast({
        msg : " addPlayerListener " + JSON.stringify(ret)
    });
});
Copy the code

Code status code

Status code Description information
1001 Start playing
1002 In the connection
1003 The connection fails
1004 The connected
1005 disconnect
1006 Stop playing
1007 Video decodes resolution information
1008 Failed to receive RTMP data. Procedure
1009 Quick url switching
1010 Snapshot succeeded or failed. Procedure
1011 Start buffer
1012 Buffer percentage
1013 Stop buffer
1014 The download speed

availability

IOS, Android

Available in version 1.0.0 and higher

openPlayer

Open the player

openPlayer({params}, callback(ret, err))

params

The rect:

  • Type: JSON object
  • Description :(mandatory) location and size of the module
  • Note: This parameter must be configured for iOS and Android.
  • Internal fields:
{x: 0, // (mandatory) Number type; The x-coordinate of the upper left corner of the module (relative to the Window or Frame it belongs to); Default value: 0 y: 0, // (Mandatory) Number type. The y-coordinate of the upper left corner of the module (relative to the Window or Frame it belongs to); Default: 0 W: api.frameWidth, // (mandatory) Number type; Width of the module; Default: width of Window or Frame h: api.frameheight // (mandatory) Number type; Module height; Default: height of owning Window or Frame}Copy the code

FixedOn:

  • Type: string
  • Description :(optional) the name of the Frame to which the module belongs. If not, the module belongs to the current Window

Fixed:

  • Type: Boolean
  • Description :(optional) whether the module scrolls with its owning Window or Frame
  • Default: true (no scrolling)

PlayBuffer:

  • Type: number type
  • Description :(optional) set buffer to 0 if no buffer is required.
  • Default value: 200

IsLowLatency:

  • Type: Boolean
  • Description :(optional) the delay can reach 200~400ms in ultra-low delay playback mode for scenarios that expect ultra-low delay, such as live broadcast dolls.
  • Default: false (disabled)

IsFastStartup:

  • Type: Boolean
  • Description :(optional) set fast startup, if CDN cache GOP, daniulive player can quickly out frames;
  • Default: true (seconds on)

IsMute:

  • Type: Boolean
  • Description :(optional) set real-time mute/unmute during playback;
  • Default: false (unmute)

IsHardwareDecoder:

  • Type: Boolean
  • Description :(optional) set whether to play with hard decoding, hard decoding/soft decoding;
  • Default: false (soft solution)

Url:

  • Type: string
  • Description :(mandatory) supports RTMP and RTSP address types (the type control is for developers to determine by themselves, and the module does not make address restriction judgment logic).

callback(ret, err)

Ret:

  • Type: JSON object
  • Internal fields:
{status: true, // Boolean; true||false }Copy the code

Err:

  • Type: JSON object
  • Internal fields:
{
    msg : ''
}
Copy the code

The sample code

var demo = api.require('daniuPlayer'); OpenPlayer ({rect: {x: 5, y: 0, w: api.frameWidth-5, h: 200}, playBuffer: 200, // default 200ms isLowLatency: False, // Low latency, default value isFastStartup: true, // Whether to enable isFastStartup: true, default value true: enable isFastStartup: true, // Whether to enable isMute: False, // Whether to mute default false: unmute true: mute isHardwareDecoder: false, // Whether to hard unmute Default false: soft unmute true: hard unmute URL: _deviceid, fixedOn: api.frameName, fixed : true }, function(ret, err) { api.toast({ msg : " openPlayer " + JSON.stringify(ret) + " " + JSON.stringify(err) }); });Copy the code

availability

IOS, Android

Available in version 1.0.0 and higher

hidePlayer

Hide player

hidePlayer(callback(ret,err))

callback(ret, err)

Ret:

  • Type: JSON object
  • Internal fields:
{status: true, // Boolean; true||false }Copy the code

Err:

  • Type: JSON object
  • Internal fields:
{
    msg : ''
}
Copy the code

The sample code

var demo = api.require('daniuPlayer');
demo.hidePlayer();
Copy the code

availability

IOS, Android

Available in version 1.0.0 and higher

showPlayer

Display player

hidePlayer(callback(ret,err))

callback(ret, err)

Ret:

  • Type: JSON object
  • Internal fields:
{status: true, // Boolean; true||false }Copy the code

Err:

  • Type: JSON object
  • Internal fields:
{
    msg : ''
}
Copy the code

The sample code

var demo = api.require('daniuPlayer');
demo.showPlayer();
Copy the code

availability

IOS, Android

Available in version 1.0.0 and higher

closePlayer

Close the player

closePlayer(callback(ret,err))

callback(ret, err)

Ret:

  • Type: JSON object
  • Internal fields:
{status: true, // Boolean; true||false }Copy the code

Err:

  • Type: JSON object
  • Internal fields:
{
    msg : ''
}
Copy the code

The sample code

var demo = api.require('daniuPlayer');
demo.closePlayer();
Copy the code

availability

IOS, Android

Available in version 1.0.0 and higher

switchUrl

SwitchUrl ({params}, callback(ret, err))

params

Url:

  • Type: string
  • Description :(mandatory) supports RTMP and RTSP address types (the type control is for developers to determine by themselves, and the module does not make address restriction judgment logic).

callback(ret, err)

Ret:

  • Type: JSON object
  • Internal fields:
{status: true, // Boolean; true||false }Copy the code

Err:

  • Type: JSON object
  • Internal fields:
{
    msg : ''
}
Copy the code

The sample code

var demo = api.require('daniuPlayer');
demo.switchUrl({
    url : "http://live.hkstv.hk.lxdns.com/live/hks/playlist.m3u8"
}, function(ret, err) {
    api.toast({
        msg : " switchUrl " + JSON.stringify(ret) + " " + JSON.stringify(err)
    });
});
Copy the code

availability

IOS, Android

Available in version 1.0.0 and higher

switchMute

SwitchMute ({params}, callback(ret, err))

params

IsMute:

  • Type: Boolean
  • Description :(optional) set real-time mute/unmute during playback;
  • Default: false (unmute)

callback(ret, err)

Ret:

  • Type: JSON object
  • Internal fields:
{status: true, // Boolean; true||false }Copy the code

Err:

  • Type: JSON object
  • Internal fields:
{
    msg : ''
}
Copy the code

The sample code

var demo = api.require('daniuPlayer');
demo.switchMute({
    isMute : true
}, function(ret, err) {
    api.toast({
        msg : " switchMute " + JSON.stringify(ret) + " " + JSON.stringify(err)
    });
});
Copy the code

availability

IOS, Android

Available in version 1.0.0 and higher

saveImage

Save snapshot saveImage(callback(ret, err))

callback(ret, err)

Ret:

  • Type: JSON object
  • Internal fields:
{status: true, // Boolean; true||false }Copy the code

Err:

  • Type: JSON object
  • Internal fields:
{
    msg : ''
}
Copy the code

The sample code

var demo = api.require('daniuPlayer');
demo.saveImage(function(ret, err) {
    api.toast({
        msg : " saveImage " + JSON.stringify(ret) + " " + JSON.stringify(err)
    });
});
Copy the code

availability

IOS, Android

Available in version 1.0.0 and higher

startRecorder

StartRecorder ({params}, callback(ret, err))

params

FileMaxSize:

  • Type: number type
  • Description :(optional) set the maximum size of each video file, in MB (M), ranging from 5M to 500M.
  • Default value: 200

callback(ret, err)

Ret:

  • Type: JSON object
  • Internal fields:
{status: true, // Boolean; true||false }Copy the code

Err:

  • Type: JSON object
  • Internal fields:
{
    msg : ''
}
Copy the code

The sample code

var demo = api.require('daniuPlayer');
demo.startRecorder();
Copy the code

availability

IOS, Android

Available in version 1.0.0 and higher

stopRecorder

StopRecorder (callback(RET, err))

callback(ret, err)

Ret:

  • Type: JSON object
  • Internal fields:
{status: true, // Boolean; true||false }Copy the code

Err:

  • Type: JSON object
  • Internal fields:
{
    msg : ''
}
Copy the code

The sample code

var demo = api.require('daniuPlayer');
demo.stopRecorder();
Copy the code

availability

IOS, Android

Available in version 1.0.0 and higher