NanoPlayer v5
NanoPlayer
NanoPlayer (H5Live) Public API Class 5.0.13
Kind: global class Version: 5.0.13
new NanoPlayer(playerDivId)
The constructor. The source can be loaded via script tag, AMD (requirejs) or CommonJS
| Param | Type | Description |
|---|---|---|
| playerDivId | string | The div element the player will be embedded into. |
Example
<!-- Example: load player with new video element into playerDiv -->
<div id="playerDiv"></div>
<script type="text/javascript" src="nanoplayer.5.min.js"></script>
<script type="text/javascript">
var player;
var config = {
"source": {
"entries": [
{
"h5live": {
// your rtmp stream
"rtmp": {
"url": "rtmp://bintu-play.nanocosmos.de/play",
"streamname": "XXXXX-YYYYY"
},
"server": {
"websocket": "wss://bintu-h5live.nanocosmos.de:443/h5live/stream.mp4",
"hls": "https://bintu-h5live.nanocosmos.de:443/h5live/http/playlist.m3u8",
"progressive": "https://bintu-h5live.nanocosmos.de:443/h5live/http/stream.mp4",
"webtransport": "https://bintu-h5live.nanocosmos.de:443/h5live/stream/stream.mp4" // important for MOQ playback
}
}
}
]
}
};
function initPlayer() {
player = new NanoPlayer('playerDiv');
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
}
// load player from playerDiv
document.addEventListener('DOMContentLoaded', function () {
initPlayer();
});
</script>
Example
<!-- Example: load player with existing html video element -->
<div id="playerDiv">
<video id="myPlayer"></video>
<!-- HLS PLAYBACK ONLY uses 2 video elements for playback if more than one stream is configured, required for seamless stream switching -->
<video id="myPlayer2"></video>
</div>
<script>
var player;
var config = {
"source": {
"entries": [
{
"h5live": {
// your rtmp stream
"rtmp": {
"url": "rtmp://bintu-play.nanocosmos.de/play",
"streamname": "XXXXX-YYYYY"
},
"server": {
"websocket": "wss://bintu-h5live.nanocosmos.de:443/h5live/stream.mp4",
"hls": "https://bintu-h5live.nanocosmos.de:443/h5live/http/playlist.m3u8",
"progressive": "https://bintu-h5live.nanocosmos.de:443/h5live/http/stream.mp4",
"webtransport": "https://bintu-h5live.nanocosmos.de:443/h5live/stream/stream.mp4" // important for MOQ playback
}
}
}
]
},
"playback": {
"videoId": ["myPlayer", "myPlayer2"]
}
};
function initPlayer() {
player = new NanoPlayer('playerDiv');
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
}
document.addEventListener('DOMContentLoaded', function () {
initPlayer();
});
</script>
Example
<!-- Example: load player with require.js -->
<script type="text/javascript" src="require.js"></script>
<script type="text/javascript">
var player;
requirejs.config({
paths: {
// loads the player ...
// for a local copy of the minified player use a relative path e.g. 'js/nanoplayer.5.min'
// if 'baseUrl' is defined a local path have to be relative to the base path
nanoplayer: '//demo.nanocosmos.de/nanoplayer/api/release/nanoplayer.5.min.js'
},
waitSeconds: 20, // timeout for loading modules
});
require('nanoplayer', function() {
initPlayer();
});
</script>
nanoPlayer.version : string
The version of the player.
Kind: instance property of NanoPlayer
nanoPlayer.coreversion : string
The version of the core.
Kind: instance property of NanoPlayer
nanoPlayer.viewversion : string
The version of the view.
Kind: instance property of NanoPlayer
nanoPlayer.type : string
The type of the player.
Kind: instance property of NanoPlayer
nanoPlayer.id : string
The unique id of the player.
Kind: instance property of NanoPlayer
nanoPlayer.capabilities : Array.<string>
The supported tech names of the player.
Kind: instance constant of NanoPlayer
nanoPlayer.setup(config) ⇒ Promise.<(config|error)>
Initializes the player with a given config object.
Kind: instance method of NanoPlayer
See: config
| Param | Type | Description |
|---|---|---|
| config | config | The config object for the player including sources, events, styles. |
Example
// player instance of NanoPlayer
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
nanoPlayer.destroy()
Cleans up the player and removes all nested elements from the container div.
Kind: instance method of NanoPlayer
Example
// player instance of NanoPlayer
player.destroy();
player.setup(config);
nanoPlayer.play()
Plays the player.
Kind: instance method of NanoPlayer
Example
// player instance of NanoPlayer
player.play();
nanoPlayer.pause()
Pauses the player.
Kind: instance method of NanoPlayer
Example
// player instance of NanoPlayer
player.pause();
nanoPlayer.mute()
Mutes the player.
Kind: instance method of NanoPlayer
Example
// player instance of NanoPlayer
player.mute();
nanoPlayer.unmute()
Unmutes the player.
Kind: instance method of NanoPlayer
Example
// player instance of NanoPlayer
player.unmute();
nanoPlayer.setVolume(volume)
Sets the volume of the player.
See here for more informations.
Kind: instance method of NanoPlayer
| Param | Type | Description |
|---|---|---|
| volume | number | The volume to set in a range from 0.0 to 1.0. |
Example
// player instance of NanoPlayer
player.setVolume(0.3);
nanoPlayer.updateSource(source) ⇒ Promise.<(config|error)>
Updates the source of the player.
Kind: instance method of NanoPlayer
See: config
| Param | Type | Default | Description |
|---|---|---|---|
| source | object | The object to configure the source to play, one of the following properties have to be set. | |
| [source.entries] | Array.<entry> | The source entries array for a set of streams. USE INSTEAD OF SOURCE.H5LIVE. Used to configure stream entries. Can have one to many 'entry' objects. Only one existing entry is similar than a single source. In this case no entries options are needed. | |
| [source.startIndex] | number | entries.length-1 | The index of the entry to start playback with. Can be in the range from 0 to 'entries.length-1'. |
| [source.options] | object | The object to configure the source entries options. | |
| [source.options.switch] | object | The object to configure the stream switch options like method etc. | |
| [source.options.switch.method] | string | "server" | The update method. Possible values are 'server' (default) and 'client'. |
| [source.options.switch.pauseOnError] | boolean | false | If set the player stops if an error occure during the stream switch. Default is false. |
| [source.options.switch.forcePlay] | boolean | true | If set the player starts playback in case the player is paused. Default is true. |
| [source.options.switch.fastStart] | boolean | false | DEPRECATED. Only if method is 'server'. Tries to accelerate the startup time of the new source. Default is false. |
| [source.options.switch.timeout] | number | 20 | The timeout for the update source request in seconds. If reached the error 4006 will thrown in the 'onUpdateSourceFail' event. Default is 10 seconds, valid range is between 5 and 30. |
| [source.options.switch.tag] | string | A custom field that can be any string like 'stream-800k' or '720p'. This tag will be returned in any completion event of the 'updateSource' request like 'onUpdateSourceSuccess', 'onUpdateSourceFail' and 'onUpdateSourceAbort'. | |
| [source.options.adaption] | object | The object to set an adaption for switching. | |
| [source.options.adaption.rule] | string | "deviationOfMean2" | The switch rule if multiple entries are defined. Possible values are 'deviationOfMean' (ABR automatic), 'deviationOfMean2' (ABR automatic) and 'none' (default, means only manual stream switch via 'switchStream' possible). |
| [source.options.adaption.downStep] | number | 1 | The minimum number of steps during a ABR down switch ('deviationOfMean' and 'deviationOfMean2' only). |
Example
var source = {
"entries": [
{
"index": 0,
"label": "high",
"tag": "this is a high quality stream",
"info": {
"bitrate": 1200,
"width": 1280,
"height": 720,
"framerate": 30
},
"hls": "",
"h5live": {
"rtmp": {
"url": "rtmp://bintu-play.nanocosmos.de/play",
"streamname": "XXXXX-YYYY1"
},
"server": {
"websocket": "wss://bintu-h5live.nanocosmos.de:443/h5live/stream.mp4",
"hls": "https://bintu-h5live.nanocosmos.de:443/h5live/http/playlist.m3u8",
"progressive": "https://bintu-h5live.nanocosmos.de:443/h5live/http/stream.mp4",
"webtransport": "https://bintu-h5live.nanocosmos.de:443/h5live/stream/stream.mp4" // important for MOQ playback
},
"token": "",
"security": {}
},
"bintu": {}
},
{
"index": 1,
"label": "medium",
"tag": "this is a medium quality stream",
"info": {
"bitrate": 800,
"width": 864,
"height": 480,
"framerate": 30
},
"hls": "",
"h5live": {
"rtmp": {
"url": "rtmp://bintu-play.nanocosmos.de/play",
"streamname": "XXXXX-YYYY2"
},
"server": {
"websocket": "wss://bintu-h5live.nanocosmos.de:443/h5live/stream.mp4",
"hls": "https://bintu-h5live.nanocosmos.de:443/h5live/http/playlist.m3u8",
"progressive": "https://bintu-h5live.nanocosmos.de:443/h5live/http/stream.mp4",
"webtransport": "https://bintu-h5live.nanocosmos.de:443/h5live/stream/stream.mp4" // important for MOQ playback
},
"token": "",
"security": {}
},
"bintu": {}
},
{
"index": 2,
"label": "low",
"tag": "this is a low quality stream",
"info": {
"bitrate": 400,
"width": 426,
"height": 240,
"framerate": 15
},
"hls": "",
"h5live": {
"rtmp": {
"url": "rtmp://bintu-play.nanocosmos.de/play",
"streamname": "XXXXX-YYYY3"
},
"server": {
"websocket": "wss://bintu-h5live.nanocosmos.de:443/h5live/stream.mp4",
"hls": "https://bintu-h5live.nanocosmos.de:443/h5live/http/playlist.m3u8",
"progressive": "https://bintu-h5live.nanocosmos.de:443/h5live/http/stream.mp4",
"webtransport": "https://bintu-h5live.nanocosmos.de:443/h5live/stream/stream.mp4" // important for MOQ playback
},
"token": "",
"security": {}
},
"bintu": {}
}
],
"options": {
"adaption": {
"rule": "deviationOfMean2",
"downStep": 1
},
"switch": {
'method': 'server',
'pauseOnError': false,
'forcePlay': true,
'timeout': 20
}
},
"startIndex": 2 // lowest
};
// player instance of NanoPlayer
player.updateSource(source).then(function (config) {
console.log('update source ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
Example
var source = {
"entries": [
{
"index": 0,
"label": "high", // optional
"tag": "this is a high quality stream", // optional
"info": { // optional
"bitrate": 1200,
"width": 1280,
"height": 720,
"framerate": 30
},
"h5live": {
// your rtmp stream
"rtmp": {
"url": "rtmp://bintu-play.nanocosmos.de/play",
"streamname": "XXXXX-YYYYY"
},
"server": {
"websocket": "wss://bintu-h5live.nanocosmos.de:443/h5live/stream.mp4",
"hls": "https://bintu-h5live.nanocosmos.de:443/h5live/http/playlist.m3u8",
"progressive": "https://bintu-h5live.nanocosmos.de:443/h5live/http/stream.mp4",
"webtransport": "https://bintu-h5live.nanocosmos.de:443/h5live/stream/stream.mp4" // important for MOQ playback
},
// optional (secure token)
"security": {
"token": 'awe456b367g4e6rm8f56hbe6gd8f5m8df6n8idf6tf8mfd68ndi',
"expires": '1519819200',
"options": '15',
"tag": 'anyTag'
}
}
}
]
};
// player instance of NanoPlayer
player.updateSource(source).then(function (config) {
console.log('update source initialized with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
nanoPlayer.switchStream(index) ⇒ Promise.<(config|error)>
Switch to a stream given over source entries.
Kind: instance method of NanoPlayer
See: entry
| Param | Type | Description |
|---|---|---|
| index | number | The index of the stream in the given stream set to switch to. |
Example
// player instance of NanoPlayer
player.switchStream(1).then(function (config) {
console.log('switch stream initialized with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
nanoPlayer.setAdaption(adaption)
Set a desired adaption rule or disable adaption on the fly.
Kind: instance method of NanoPlayer
See: config
| Param | Type | Description |
|---|---|---|
| adaption | object | The adaption object similar than the object 'config.source.options.adaption'. |
Example
// player instance of NanoPlayer
var adaption = {
"rule": "deviationOfMean2",
"downStep": 2
}
if (!useAdaption) {
adaption.rule = "none";
}
player.setAdaption(adaption);
nanoPlayer.requestFullscreen() ⇒ Promise.<(undefined|error)>
Request fullscreen mode for the player if not entered.
Kind: instance method of NanoPlayer
Example
// player instance of NanoPlayer
player.requestFullscreen()
.then(function (){
console.log('requestFullscreen resolved');
})
.catch(function(err) {
// error reasons can be 'denied' or 'disabled' (e.g. in audio player mode)
console.log('requestFullscreen rejected: ' + err.reason);
});
nanoPlayer.exitFullscreen() ⇒ Promise.<(undefined|error)>
Exit fullscreen mode if entered.
Kind: instance method of NanoPlayer
Example
// player instance of NanoPlayer
player.exitFullscreen()
.then(function (){
console.log('exitFullscreen resolved');
})
.catch(function(err) {
// error reasons can be 'denied' or 'disabled' (e.g. in audio player mode)
console.log('exitFullscreen rejected: ' + err.reason);
});
"onReady"
The ready event to pass in the 'config.events' object at the setup call. Fires if the player is ready to play after successful setup.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.config | config | The config object. |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onReady = function (event) {
console.log('Ready: ' + JSON.stringify(event.data.config));
}
config.events.onReady = onReady;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onPlay"
The play event to pass in the 'config.events' object at the setup call. Fires if playout is started.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.stats | object | The startup stats object. |
| data.stats.connecting | number | The time when 'player.play()' is just called in ms (always zero). |
| data.stats.connected | number | The time when the connection is established in ms (relative to 'connecting'). |
| data.stats.firstFragmentReceived | number | The time when the first fragment is received in ms (relative to 'connecting'). |
| data.stats.firstFrameRendered | number | The time when the first frame is rendered in ms (relative to 'connecting'). |
| data.stats.playable | number | The time when the buffer has enough data to start in ms (relative to 'connecting'). |
| data.stats.playing | number | The time when the playback is started in ms (relative to 'connecting'). It's the total startup time. |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onPlay = function (event) {
console.log('Playing');
console.log('play stats: ' + JSON.stringify(event.data.stats));
};
config.events.onPlay = onPlay;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onPause"
The pause event to pass in the 'config.events' object at the setup call. Fires if playout is paused.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.reason | pausereason | The reason of pausing. |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onPause = function (event) {
console.log('Pause');
if (event.data.reason !== 'normal') {
alert('Paused with reason: ' + event.data.reason);
}
};
config.events.onPause = onPause;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onLoading"
The load event to pass in the 'config.events' object at the setup call. Fires if playout was stopped or player is ready after setup and tries to play.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.connectDelay | number | The time in milliseconds to wait for initializing the connection to the server to get the stream. Is zero if no reconnect is imminent. |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onLoading = function (event) {
console.log('Loading with delay of ' + event.data.connectDelay + ' milliseconds');
};
config.events.onLoading = onLoading;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onStartBuffering"
The start buffering event to pass in the 'config.events' object at the setup call. Fires if playout is started but no media is available.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object (empty). |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onStartBuffering = function (event) {
console.log('Buffering');
};
config.events.onStartBuffering = onStartBuffering;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onStopBuffering"
The stop buffering event to pass in the 'config.events' object at the setup call. Fires if playout resumes after buffering.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object (empty). |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onStopBuffering = function (event) {
console.log('Resume');
};
config.events.onStopBuffering = onStopBuffering;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onError"
The error event to pass in the 'config.events' object at the setup call. Fires if any kind of error occures.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.code | errorcode | The error code. |
| data.message | string | The error cause as human readable string. |
| [data.playback] | object | The optional data playback object (since 4.28.0). Includes current playback stats. Only available if error is a startup error. |
| data.playback.bufferDelayCurrent | number | Buffer delay in ms experienced at the time of the error. Always available. |
| data.playback.bitrateCurrent | number | The bitrate in Bit/s of playback at the time the error occurred. Always available. |
| data.playback.framerateCurrent | number | Playback framerate per second at the time of the error. Always available. |
| [data.state] | object | The optional data state object (since 4.28.0). Includes all timestamps of the startup phase that have been reached before the error occurred. Only available if error is a startup error. |
| [data.state.connected] | number | Timestamp in ms indicating when the connection was established (relative to load start). Optional. |
| [data.state.firstFragmentReceived] | number | Time in ms at which the first fragment of media data was received (relative to load start). Optional. |
| [data.state.firstFrameRendered] | number | Time in ms when the first frame was rendered (relative to load start). Optional. |
| [data.state.playable] | number | Timestamp in ms indicating when playback was ready to begin (relative to load start). Optional. |
| [data.state.playing] | number | Timestamp in ms indicating when playback actually started (relative to load start). Optional. |
| data.state.error | number | Timestamp in ms marking when the error occurred (relative to load start). Always available. |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onError = function (event) {
if (event.data.state) {
alert('Startup Error: ' + event.data.code + ' ' + event.data.message + ' at ' + event.data.state.error + 'ms after load start');
}
else {
alert('Error: ' + event.data.code + ' ' + event.data.message);
}
};
config.events.onError = onError;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onStats"
The stats event to pass in the 'config.events' object at the setup call. Fires if the player has measured statistics.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.stats | object | The stats object. |
| data.stats.currentTime | number | The current time of the video. |
| data.stats.playout | object | The playout object. |
| data.stats.playout.start | number | The start play time of the video. |
| data.stats.playout.end | number | The end play time of the video. |
| data.stats.buffer | object | The buffer object. |
| data.stats.buffer.start | number | The start buffer time of the video. |
| data.stats.buffer.end | number | The end buffer time of the video. |
| data.stats.buffer.delay | object | The delay buffer object. |
| data.stats.buffer.delay.current | number | The current delay time. |
| data.stats.buffer.delay.avg | number | The average delay time over the last second. |
| data.stats.buffer.delay.min | number | The minimum delay time over the last second. |
| data.stats.buffer.delay.max | number | The maximum delay time over the last second. |
| data.stats.bitrate | object | The bitrate object. |
| data.stats.bitrate.current | number | The current bitrate in Bit/s. Is '0' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
| data.stats.bitrate.avg | number | The average bitrate in Bit/s over the last 10 seconds. Is '0' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
| data.stats.bitrate.min | number | The minimum bitrate in Bit/s over the last 10 seconds. Is '0' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
| data.stats.bitrate.max | number | The maximum bitrate in Bit/s over the last 10 seconds. Is '0' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
| data.stats.framerate | object | The framerate object. |
| data.stats.framerate.current | number | The current network framerate. Is '0' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
| data.stats.framerate.avg | number | The average network framerate over the last 10 seconds. Is '0' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
| data.stats.framerate.min | number | The minimum network framerate over the last 10 seconds. Is '0' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
| data.stats.framerate.max | number | The maximum network framerate over the last 10 seconds. Is '0' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
| data.stats.playbackrate | object | The playbackrate object. (since 4.14.1) |
| data.stats.playbackrate.current | number | The current video playbackrate. (since 4.14.1) |
| data.stats.playbackrate.avg | number | The average video playbackrate over the last 10 seconds. (since 4.14.1) |
| data.stats.playbackrate.min | number | The minimum video playbackrate over the last 10 seconds. (since 4.14.1) |
| data.stats.playbackrate.max | number | The maximum video playbackrate over the last 10 seconds. (since 4.14.1) |
| data.stats.buffergoal | object | The buffergoal object. Values used by the latency control (since 4.14.1) |
| data.stats.buffergoal.base | number | The suggested calculated buffergoal value depending on the latency control mode and playback conditions (since 4.14.1) |
| data.stats.buffergoal.real | number | The final calculated buffergoal value including offsets (since 4.14.1) |
| data.stats.buffergoal.min | number | The minimum possible buffergoal value. (since 4.14.1) |
| data.stats.buffergoal.max | number | The maximum possible buffergoal value. (since 4.14.1) |
| data.stats.quality | object | The video playback quality object. |
| data.stats.quality.corruptedVideoFrames | number | The total number of corrupted video frames. |
| data.stats.quality.corruptedVideoFramesCurrent | number | The number of corrupted video frames within the last second. |
| data.stats.quality.creationTime | number | The time in miliseconds since the start of the navigation and the creation of the video element. |
| data.stats.quality.droppedVideoFrames | number | The total number of dropped video frames. |
| data.stats.quality.droppedVideoFramesCurrent | number | The number of dropped video frames within the last second. |
| data.stats.quality.sourceBufferDetached | number | Whether the underlying media source buffer was detached and recovered since the last quality tick (0 or 1). |
| data.stats.quality.totalVideoFrames | number | The total number of created and dropped video frames since creation of the video element. |
Example
// player instance of NanoPlayer
var onStats = function (event) {
console.log('Stats: ' + JSON.stringify(event.data.stats));
};
config.events.onStats = onStats;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onMetaData"
The metadata event to pass in the 'config.events' object at the setup call. The config param 'playback.metadata' have to be set to true. Fires if the player receives metadata.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.handlerName | string | The name of the metadata handler. |
| data.message | * | The metadata message. |
| data.streamTime | number | The timestamp of the metadata in relation to currentTime. |
Example
// player instance of NanoPlayer
var onMetaData = function (event) {
console.log('MetaData: ' + JSON.stringify(event.data));
};
config.events.onMetaData = onMetaData;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onMute"
The mute event to pass in the 'config.events' object at the setup call. Fires if the player is muted.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.volume | number | The current volume in a range from 0.0 to 1.0. |
Example
// player instance of NanoPlayer
var onMute = function (event) {
console.log('Muted with volume: ' + event.data.volume);
};
config.events.onMute = onMute;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onUnmute"
The unmute event to pass in the 'config.events' object at the setup call. Fires if the player is unmuted.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.volume | number | The current volume in a range from 0.0 to 1.0. |
Example
// player instance of NanoPlayer
var onUnmute = function (event) {
console.log('Unmuted with volume: ' + event.data.volume);
};
config.events.onUnmute = onUnmute;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onVolumeChange"
The volume change event to pass in the 'config.events' object at the setup call. Fires if the player's volume has changed.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.volume | number | The current volume in a range from 0.0 to 1.0. |
Example
// player instance of NanoPlayer
var onVolumeChange = function (event) {
console.log('Volume: ' + event.data.volume);
};
config.events.onVolumeChange = onVolumeChange;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onStreamInfo"
The stream info event to pass in the 'config.events' object at the setup call. Fires if informations about a stream is available right before playback starts.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.streamInfo | object | The stream info object. |
| data.streamInfo.url | string | The complete stream url with parameters. |
| data.streamInfo.rtmp | object | The rtmp stream object. |
| data.streamInfo.rtmo.url | string | The rtmp stream url. |
| data.streamInfo.rtmp.streamname | string | The rtmp streamname. |
| data.streamInfo.haveAudio | boolean | Indicates if the stream contains audio. |
| data.streamInfo.haveVideo | boolean | Indicates if the stream contains video. |
| data.streamInfo.audioInfo | object | null | The audio info object. Is 'null' if the stream contains no audio. |
| data.streamInfo.audioInfo.bitsPerSample | number | null | The bits per sample. Is 'null' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
| data.streamInfo.audioInfo.sampleRate | number | null | The audio sample rate. Is 'null' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
| data.streamInfo.audioInfo.channels | number | null | The number of audio channels. Is 'null' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
| data.streamInfo.videoInfo | object | null | The stream info object. Is 'null' if the stream contains no video. |
| data.streamInfo.videoInfo.width | number | null | The width of the video. Is 'null' if not available. |
| data.streamInfo.videoInfo.height | number | null | The height of the video. Is 'null' if not available. |
| data.streamInfo.videoInfo.frameRate | number | null | The video frame rate. Is 'null' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
Example
// player instance of NanoPlayer
var onStreamInfo = function (event) {
console.log('StreamInfo: ' + JSON.stringify(event.data.streamInfo));
};
config.events.onStreamInfo = onStreamInfo;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onStreamInfoUpdate"
The stream info event to pass in the 'config.events' object at the setup call. Fires if the stream format has changed during playback.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.streamInfo | object | The stream info object. |
| data.streamInfo.url | string | The complete stream url with parameters. |
| data.streamInfo.haveAudio | boolean | Indicates if the stream contains audio. |
| data.streamInfo.haveVideo | boolean | Indicates if the stream contains video. |
| data.streamInfo.audioInfo | object | null | The audio info object. Is 'null' if the stream contains no audio. |
| data.streamInfo.audioInfo.bitsPerSample | number | null | The bits per sample. Is 'null' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
| data.streamInfo.audioInfo.sampleRate | number | null | The audio sample rate. Is 'null' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
| data.streamInfo.audioInfo.channels | number | null | The number of audio channels. Is 'null' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
| data.streamInfo.videoInfo | object | null | The stream info object. Is 'null' if the stream contains no video. |
| data.streamInfo.videoInfo.width | number | null | The width of the video. Is 'null' if not available. |
| data.streamInfo.videoInfo.height | number | null | The height of the video. Is 'null' if not available. |
| data.streamInfo.videoInfo.frameRate | number | null | The video frame rate. Is 'null' if not available. NOT AVAILABLE FOR HLS PLAYBACK. |
Example
// player instance of NanoPlayer
var onStreamInfoUpdate = function (event) {
console.log('StreamInfo updated: ' + JSON.stringify(event.data.streamInfo));
};
config.events.onStreamInfoUpdate = onStreamInfoUpdate;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onWarning"
The error event to pass in the 'config.events' object at the setup call. Fires if something is not as expected, but functionality works.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.message | string | The warning as human readable string. |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onWarning = function (event) {
console.log('Warning: ' + event.data.message);
};
config.events.onWarning = onWarning;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onDestroy"
The destroy event to pass in the 'config.events' object at the setup call. Fires if the player is destroyed.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object (empty). |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onDestroy = function (event) {
console.log('player destroy');
};
config.events.onDestroy = onDestroy;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onUpdateSourceInit"
The event to signal that the update source request is initialized. This is always the start event, an completion event will follow.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.source | object | The current source object. |
| data.entry | object | The current source entry. |
| data.rule | string | The adaption switch rule. |
| data.options | object | The switch options object. |
| data.tag | string | The custom tag string given in the options object of the 'updateSource' call. Is an empty string if not set. |
| data.count | number | The count of the update source request to identify the paired start and completion event. The start event is 'onUpdateSourceInit' and completion events are 'onUpdateSourceSuccess', 'onUpdateSourceFail' and 'onUpdateSourceAbort' |
| data.type | string | The switch type. Here always 'update'. |
| data.id | number | The id of the update source request to identify the paired start and completion event. The start event is 'onUpdateSourceInit' and completion events are 'onUpdateSourceSuccess', 'onUpdateSourceFail' and 'onUpdateSourceAbort' |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onUpdateSourceInit = function (event) {
console.log('update source init with source: ' + JSON.stringify(event.data.source) + ' and options: ' + JSON.stringify(event.data.options));
console.log('update source tag: ' + event.data.tag);
console.log('update source count: ' + event.data.count);
};
config.events.onUpdateSourceInit = onUpdateSourceInit;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onUpdateSourceSuccess"
The event to signal that the update source request is succeeded. Fires if the source is updated. This is an completion event that follows on an start event.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.source | object | The current source object. |
| data.entry | object | The current source entry. |
| data.rule | string | The adaption switch rule. |
| data.tag | string | The custom tag string given in the options object of the 'updateSource' call. Is an empty string if not set. |
| data.count | number | The count of the update source request to identify the paired start and completion event. The start event is 'onUpdateSourceInit' and completion events are 'onUpdateSourceSuccess', 'onUpdateSourceFail' and 'onUpdateSourceAbort' |
| data.type | string | The switch type. Here always 'update'. |
| data.id | number | The id of the update source request to identify the paired start and completion event. The start event is 'onUpdateSourceInit' and completion events are 'onUpdateSourceSuccess', 'onUpdateSourceFail' and 'onUpdateSourceAbort' |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onUpdateSourceSuccess = function (event) {
console.log('update source success with entry: ' + JSON.stringify(event.data.entry) + ', with tag: ' + event.data.tag + ' and count: ' + event.data.count);
};
config.events.onUpdateSourceSuccess = onUpdateSourceSuccess;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onUpdateSourceFail"
The event to signal that the update source request is failed. Fired if an error occure during the update. This is an completion event that follows on an start event.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data.source | object | The current source object. |
| data.entry | object | The current source entry. |
| data.rule | string | The adaption switch rule. |
| data.code | object | The error code. Similar to the errorcodes. |
| data.message | object | The error message. |
| data.tag | string | The custom tag string given in the options object of the 'updateSource' call. Is an empty string if not set. |
| data.count | number | The count of the update source request to identify the paired start and completion event. The start event is 'onUpdateSourceInit' and completion events are 'onUpdateSourceSuccess', 'onUpdateSourceFail' and 'onUpdateSourceAbort' |
| data.type | string | The switch type. Here always 'update'. |
| data.id | number | The id of the update source request to identify the paired start and completion event. The start event is 'onUpdateSourceInit' and completion events are 'onUpdateSourceSuccess', 'onUpdateSourceFail' and 'onUpdateSourceAbort' |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onUpdateSourceFail = function (event) {
console.log('update source fail with entry: ' + JSON.stringify(event.data.entry) + ', with error code: ' + event.data.code + ' and error message: ' + event.data.message);
console.log('update source tag: ' + event.data.tag);
console.log('update source count: ' + event.data.count);
};
config.events.onUpdateSourceFail = onUpdateSourceFail;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onUpdateSourceAbort"
The event to signal that the update source request is aborted. Reasons can be an equal source ('equalsource'), a superseding ('superseded') or an to less time range between two 'updateSource' calls ('frequency'). This is an completion event that follows on an start event.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.source | object | The current source object. |
| data.entry | object | The current source entry. |
| data.rule | string | The adaption switch rule. |
| data.reason | string | The abort reason. Possible values are 'equalsource', 'superseded' and 'frequency'. |
| data.tag | string | The custom tag string given in the options object of the 'updateSource' call. Is an empty string if not set. |
| data.count | number | The count of the update source request to identify the paired start and completion event. The start event is 'onUpdateSourceInit' and completion events are 'onUpdateSourceSuccess', 'onUpdateSourceFail' and 'onUpdateSourceAbort' |
| data.type | string | The switch type. Here always 'update'. |
| data.id | number | The id of the update source request to identify the paired start and completion event. The start event is 'onUpdateSourceInit' and completion events are 'onUpdateSourceSuccess', 'onUpdateSourceFail' and 'onUpdateSourceAbort' |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onUpdateSourceAbort = function (event) {
console.log('update source abort with entry: ' + JSON.stringify(event.data.entry) + ' and reason: ' + event.data.reason);
console.log('tag: ' + event.data.tag);
console.log('count: ' + event.data.count);
};
config.events.onUpdateSourceAbort = onUpdateSourceAbort;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onSwitchStreamInit"
The event to signal that an stream switch request is initialized. Can be triggered by an adaptive rule (ABR) request or via 'switchStream'. This is always the start event, an completion event will follow.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.source | object | The current source object. |
| data.entry | object | The current source entry. |
| data.rule | string | The adaption switch rule. |
| data.options | object | The switch options object. |
| data.tag | string | A static string in format: "data.entry.h5live.rtmp.streamname + ' streamSwitch ' + data.id". |
| data.count | number | The count of the switch stream request to identify the paired start and completion event. The start event is 'onSwitchStreamInit' and completion events are 'onSwitchStreamSuccess', 'onSwitchStreamFail' and 'onSwitchStreamAbort' |
| data.type | string | The switch type. Possible values are 'up', 'down' (in case of adaptive stream switch) and 'direct' (switch via 'switchStream'). |
| data.id | number | The id of the switch stream request to identify the paired start and completion event. The start event is 'onSwitchStreamInit' and completion events are 'onSwitchStreamSuccess', 'onSwitchStreamFail' and 'onSwitchStreamAbort' |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onSwitchStreamInit = function (event) {
console.log('switch stream init by rule ' + event.data.rule + ' from type ' + event.data.type + 'with entry: ' + JSON.stringify(event.data.entry) + ' and options: ' + JSON.stringify(event.data.options));
console.log('switch stream tag: ' + event.data.tag);
console.log('switch stream count: ' + event.data.count);
};
config.events.onSwitchStreamInit = onSwitchStreamInit;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onSwitchStreamSuccess"
The event to signal that the switch stream request is succeeded. Fires if the source is updated. This is an completion event that follows on an start event.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.source | object | The current source object. |
| data.entry | object | The current source entry. |
| data.rule | string | The adaption switch rule. |
| data.tag | string | A static string in format: "data.entry.h5live.rtmp.streamname + ' streamSwitch ' + data.id." |
| data.count | number | The count of the switch stream request to identify the paired start and completion event. The start event is 'onSwitchStreamInit' and completion events are 'onSwitchStreamSuccess', 'onSwitchStreamFail' and 'onSwitchStreamAbort' |
| data.type | string | The switch type. Possible values are 'up', 'down' (in case of adaptive stream switch) and 'direct' (switch via 'switchStream'). |
| data.id | number | The id of the switch stream request to identify the paired start and completion event. The start event is 'onSwitchStreamInit' and completion events are 'onSwitchStreamSuccess', 'onSwitchStreamFail' and 'onSwitchStreamAbort' |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onSwitchStreamSuccess = function (event) {
console.log('switch stream success by rule ' + event.data.rule + ' from type ' + event.data.type + 'with entry: ' + JSON.stringify(event.data.entry) + ' with tag: ' + event.data.tag + ' and count: ' + event.data.count);
};
config.events.onSwitchStreamSuccess = onSwitchStreamSuccess;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onSwitchStreamFail"
The event to signal that the switch stream request is failed. Fired if an error occure during the update. This is an completion event that follows on an start event.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data.source | object | The current source object. |
| data.entry | object | The current source entry. |
| data.rule | string | The adaption switch rule. |
| data.code | object | The error code. Similar to the errorcodes. |
| data.message | object | The error message. |
| data.tag | string | A static string in format: "data.entry.h5live.rtmp.streamname + ' streamSwitch ' + data.id". |
| data.count | number | The count of the switch stream request to identify the paired start and completion event. The start event is 'onSwitchStreamInit' and completion events are 'onSwitchStreamSuccess', 'onSwitchStreamFail' and 'onSwitchStreamAbort' |
| data.type | string | The switch type. Possible values are 'up', 'down' (in case of adaptive stream switch) and 'direct' (switch via 'switchStream'). |
| data.id | number | The id of the switch stream request to identify the paired start and completion event. The start event is 'onSwitchStreamInit' and completion events are 'onSwitchStreamSuccess', 'onSwitchStreamFail' and 'onSwitchStreamAbort' |
| state | state | The player state. |
Example
// player instance of NanoPlayer
var onSwitchStreamFail = function (event) {
console.log('switch stream fail by rule ' + event.data.rule + ' from type ' + event.data.type + 'with entry: ' + JSON.stringify(event.data.entry) + ' with error code: ' + event.data.code + ' and error message: ' + event.data.message);
console.log('switch stream tag: ' + event.data.tag);
console.log('switch stream count: ' + event.data.count);
};
config.events.onSwitchStreamFail = onSwitchStreamFail;
player.setup(config).then(function (config) {
console.log('setup ok with config: ' + JSON.stringify(config));
}, function (error) {
console.log(error);
});
"onSwitchStreamAbort"
The event to signal that the switch stream request is aborted. Reasons can be an equal source ('equalsource'), a superseding ('superseded') or an to less time range between two 'switchStream' calls ('frequency'). This is an completion event that follows on an start event.
Kind: event emitted by NanoPlayer
See: config
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The event name. |
| player | string | The player name (id of the playerDiv). |
| id | string | The unique id of the player instance. |
| version | string | The version of the player. |
| data | object | The data object. |
| data.source | object | The current source object. |
| data.entry | object | The current source entry. |
| data.rule | string | The adaption switch rule. |
| data.reason | string | The abort reason. Possible values are 'equalsource', 'superseded' and 'frequency'. |
| data.tag | string | A static string in format: "data.entry.h5live.rtmp.streamname + ' streamSwitch ' + data.id." |
| data.count | number | The count of the switch stream request to identify the paired start and completion event. The start event is 'onSwitchStreamInit' and completion events are 'onSwitchStreamSuccess', 'onSwitchStreamFail' and 'onSwitchStreamAbort' |
| data.type | string | The switch type. Possible values are 'up', 'down' (in case of adaptive stream switch) and 'direct' (switch via 'switchStream'). |
| data.id | number | The id of the switch stream request to identify the paired start and completion event. The start event is 'onSwitchStreamInit' and completion events are 'onSwitchStreamSuccess', 'onSwitchStreamFail' and 'onSwitchStreamAbort' |
| state | state | The player state. |