nanoStream Player: introduction & getting started
The nanoStream Player is the JavaScript player for live streams on the nanocosmos platform. It plays with ultra-low latency in all modern browsers, picks the best playback technology for each device on its own, and switches between ABR renditions to match the viewer's bandwidth. This page gets a player running on your page; the configuration reference covers every option.
How it plays
The player chooses the playback technology automatically. You don't need to configure it.
| Technology | Used on |
|---|---|
| MOQ (Media over QUIC) | Browsers with WebTransport and WebCodecs support. The primary technology. |
| H5Live over WebSocket / Media Source Extensions | All other desktop and Android browsers, and iOS 17.1+ through ManagedMediaSource. The fallback. |
| H5Live low-latency HLS | iOS before 17.1 and iOS WebViews without ManagedMediaSource, and Safari on macOS if you enable playback.allowSafariHlsFallback |
If MOQ isn't available or its connection probe fails, the player falls back to H5Live by itself. See Playback technologies for the full matrix.
Ways to add the player
| Option | Effort | When to use |
|---|---|---|
| Embed code from the Dashboard or Builder Hub (iframe) | Copy and paste | Fastest way; no code to maintain. See Embed the player. |
| JavaScript player on your page | A few lines of JS | You want events, custom UI, ABR control, or tokens from your backend. This page. |
| Native app | WebView | Load your player page in an Android or iOS WebView. See Supported browsers & devices. |
Load the player library
Add the script to your page. It defines the global NanoPlayer class.
<script src="https://demo.nanocosmos.de/nanoplayer/api/release/nanoplayer.5.min.js"></script>
This is the release build of player version 5: nanoplayer.5.min.js always loads the latest 5.x release (currently 5.1.1) and is cached for 10 minutes, so an update reaches your viewers within minutes. To pin a version, load nanoplayer.5.x.y.min.js instead, for example nanoplayer.5.1.1.min.js. The library also loads via AMD (require.js) or CommonJS.
Load nanoplayer.5.min.js. nanoplayer.4.min.js is the legacy v4 player; see Migration & legacy versions.
Quickstart: play a stream
You need either a stream group ID or a stream name from the nanoStream Dashboard, the Builder Hub or the REST API. Use the playout stream name, not the ingest name.
Option 1: stream group (recommended)
A stream group is a stream with all its ABR renditions. Pass its ID once and the player fetches all renditions, applies ABR and handles the endpoints itself. This works for a single stream too.
<div id="playerDiv"></div>
<script src="https://demo.nanocosmos.de/nanoplayer/api/release/nanoplayer.5.min.js"></script>
<script>
var config = {
source: {
group: {
id: "xxxxxxxx-zzzz-yyyy-aaaa-aaabbbcccddd", // your stream group ID
startQuality: "medium" // optional, default: lowest rendition
// security: { jwtoken: "<YOUR_JWT>" } // only for secure playback
}
},
playback: {
autoplay: true,
automute: true,
muted: false,
faststart: true,
latencyControlMode: "balancedadaptive"
},
style: {
width: "auto",
height: "auto"
},
events: {
onError: function (e) {
console.log("player error " + e.data.code + ": " + e.data.message);
}
}
};
document.addEventListener("DOMContentLoaded", function () {
var player = new NanoPlayer("playerDiv");
player.setup(config).then(function (config) {
console.log("setup success");
}, function (error) {
console.log("setup failed: " + error.message);
});
});
</script>
You don't need source.options for a group: the player applies ABR automatically. group.id also accepts the group's passthrough stream name (XXXXX-YYYYY) instead of the UUID.
Option 2: stream name
Play one stream by name. defaults.service: "bintu" fills in all server URLs for you. You need it here: without it, a stream name without server URLs fails setup with error 5007.
var config = {
source: {
defaults: { service: "bintu" },
entries: [
{
h5live: {
rtmp: { streamname: "XXXXX-YYYYY" } // your playout stream name
// security: { jwtoken: "<YOUR_JWT>" } // only for secure playback
}
}
]
},
playback: {
autoplay: true,
automute: true,
muted: false,
faststart: true,
latencyControlMode: "balancedadaptive"
}
};
Option 3: stream ID
var config = {
source: {
entries: [
{ bintu: { streamid: "1111-2222-3333-4444-5555" } } // your stream ID, not the name
]
}
};
Option 4: explicit server URLs
Only needed if you don't use the bintu defaults, for example with your own domains. Every endpoint must be set, including webtransport, or MOQ isn't available for that entry.
var config = {
source: {
entries: [
{
h5live: {
rtmp: {
url: "rtmp://bintu-play.nanocosmos.de:80/play",
streamname: "XXXXX-YYYYY"
},
server: {
websocket: "wss://bintu-h5live.nanocosmos.de:443/h5live/stream/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"
}
}
}
]
}
};
For custom domains, source.general.baseDomain or source.general.serverDomain is simpler. See Player configuration reference.
Wire up events at setup
Pass event handlers in config.events. Don't attach them later inside the setup().then() callback: the player can fire onReady, onStreamInfo and onPlay before that callback runs, and your UI then misses them.
config.events = {
onReady: function (e) { setStatus("connecting"); },
onPlay: function (e) { setStatus("playing"); },
onPause: function (e) { setStatus("paused: " + e.data.reason); },
onError: function (e) { setStatus("error " + e.data.code + ": " + e.data.message); },
onStats: function (e) { renderStats(e.data.stats); }
};
See Events & error codes.
Control the player
| Method | What it does |
|---|---|
setup(config) | Initialise with a config. Returns a promise. |
play() / pause() | Start or pause playback. pause() keeps the connection open. |
mute() / unmute() / setVolume(0.0–1.0) | Audio control (setVolume isn't available for HLS playback) |
updateSource(source) | Play a different stream or group in the same player, without rebuilding it |
switchStream(index) | Switch to another rendition of the current source |
setAdaption(adaption) | Change or disable the ABR rule at runtime |
requestFullscreen() / exitFullscreen() | Fullscreen control. Returns a promise. |
destroy() | Stop playback, close the connection and remove the player from the page |
There is no stop() method. To stop and end the session, call destroy(); to restart afterwards, create a new NanoPlayer and call setup() again.
Frameworks
The pattern is the same everywhere: load the script once, render a div with an ID, create the player after the element exists, and destroy it when the component unmounts.
React
import { useEffect } from "react";
export default function LivePlayer({ streamName }) {
useEffect(() => {
const player = new window.NanoPlayer("playerDiv");
player.setup({
source: {
defaults: { service: "bintu" },
entries: [{ h5live: { rtmp: { streamname: streamName } } }]
},
playback: { autoplay: true, automute: true, muted: false }
});
return () => player.destroy();
}, [streamName]);
return <div id="playerDiv" />;
}
Load nanoplayer.5.min.js in public/index.html. Sample app: https://github.com/nanocosmos/nanoplayer-react-sample
Vue
Load the script in index.html, keep the config in data(), and create the player in mounted() with new window.NanoPlayer("playerDiv"). Sample: https://github.com/nanocosmos/nanoplayer-vuejs-sample
WordPress
Add a Custom HTML block with the script tag, a sized wrapper div around playerDiv, and the setup script from Option 2 above. Without a wrapper that has a width and height, the player isn't visible.
Analytics from the player
To see playtime, latency, startup time and buffering in nanoStream Analytics, add a metrics block with your account ID and key. Without it the player sends no metrics. See Player configuration reference.
Troubleshooting first steps
| Symptom | Check |
|---|---|
Nothing appears, NanoPlayer is not defined | The script tag is missing, blocked, or malformed (for example a missing >) |
Player stays on "connecting", then error 2001 | The stream isn't live, or you used the ingest name instead of the playout name |
Error 5004 | The source config is malformed or missing (group.id or rtmp.streamname) |
Error 4901 / 4903 | Secure playback: token invalid, expired or in the wrong place. See Playback tokens. |
| No sound on start | Expected: browsers only autoplay muted. See Player features. |
More in Events & error codes and Troubleshooting.
Next steps
- Player configuration reference: every config key
- Player features: fast start, reconnect, autoplay, stream switching and more
- Embed the player: the no-code iframe embed
- Playback tokens: secure playback with JWTs
Try it in the Builder Hub: Instant Live Stream starts a test stream and plays it in the nanoStream Player, so you can copy a working config. Start for Free