Embed the player on your website
You embed the nanoStream Player in one of two ways: with the JavaScript API (nanoplayer.5.min.js) for full control, or with a ready-hosted iframe for the quickest result. Both use MOQ with automatic H5Live fallback and work on desktop and mobile browsers.
Which option to use
| Option | Best for | Limits |
|---|---|---|
| JavaScript API | Production sites, custom UI, events, stream switching, token workflows | You write a few lines of JavaScript |
| Hosted iframe embed | CMS pages, quick tests, sites where you can't add scripts | Configuration via URL parameters only; no domain-bound (referrer-restricted) tokens |
| Your own player page in an iframe | Isolating the player from the rest of your page | You host the player page yourself |
For most sites, embedding the player directly in the page with the JavaScript API is the best choice. Use an iframe only when your setup requires it.
You don't have to write the snippet from scratch. The nanoStream Dashboard shows ready-to-copy code snippets for every stream. In the Builder Hub, Share and embed gives you an embed snippet too, and Developer mode shows the player code for your stream on every tool page that plays it.
What you need
- A live stream and either its stream group ID, its stream name (
XXXXX-YYYYY) or its stream ID. You find them in the Builder Hub, the nanoStream Dashboard or the nanoStream REST API. - For token-protected organisations: a playback token. See Playback tokens.
Embed with the JavaScript API
-
Add a container element and load the player script:
<div id="playerDiv"></div><script src="https://demo.nanocosmos.de/nanoplayer/api/release/nanoplayer.5.min.js"></script> -
Create a configuration. With a stream group (recommended, works for single streams and ABR):
<script>var config = {source: {group: {id: '<STREAM_GROUP_ID>', // your stream group IDstartQuality: 'medium' // optional: high | medium-high | medium | medium-low | low}},playback: {autoplay: true,automute: true,muted: false,faststart: true,latencyControlMode: 'balancedadaptive'}};</script> -
Create the player and call
setup()once the page has loaded:<script>var player;document.addEventListener('DOMContentLoaded', function () {player = new NanoPlayer('playerDiv');player.setup(config).then(function (config) {console.log('setup success');}, function (error) {console.log(error.message);});});</script> -
Open the page while the stream is live. The player picks MOQ or H5Live automatically.
Load nanoplayer.5.min.js, not a 4.x script. Check that the <script> tag is closed correctly: a missing > stops the script from loading and NanoPlayer is undefined.
Source options
Use exactly one of these source forms:
| Source form | Config | Since |
|---|---|---|
| Stream group | source.group: { id, startQuality, security } | 4.18.0 |
| Stream name with nanocosmos defaults | source.defaults.service: 'bintu' + source.entries[].h5live.rtmp.streamname | 4.13.0 |
| Stream ID | source.entries[].bintu.streamid | |
| Custom server URLs | source.entries[].h5live.rtmp + h5live.server (include webtransport for MOQ) |
Stream name with defaults:
var config = {
source: {
defaults: { service: 'bintu' },
entries: [
{ h5live: { rtmp: { streamname: 'XXXXX-YYYYY' } } } // your stream name
]
},
playback: { autoplay: true, automute: true, muted: false, faststart: true }
};
Stream ID:
var config = {
source: {
entries: [
{ bintu: { streamid: '<STREAM_ID>' } } // stream ID, not the stream name
]
}
};
With a group source, the player chooses the ABR rule and start rendition itself. Set the start rendition with group.startQuality; don't add source.startIndex or source.options.adaption next to group. Custom server URLs are only needed for special setups; see Playback technologies.
All configuration keys are listed in the Player configuration reference.
Token-protected streams
If secure playback is enabled for your organisation, add the playback token as a security object to the group or entry:
var config = {
source: {
group: {
id: '<STREAM_GROUP_ID>',
security: { jwtoken: '<YOUR_JWT>' }
}
}
};
Create tokens on your server and hand them to the page; never put API keys in the page. See Playback tokens.
Frameworks and CMS
-
React: load the script in
public/index.html, render<div id="playerDiv" />, and create the player inuseEffect(() => { ... }, [])(orcomponentDidMount). Sample: https://github.com/nanocosmos/nanoplayer-react-sample -
Vue.js: load the script in
index.html, put the config indata(), and createnew window.NanoPlayer('playerDiv')inmounted(). Sample: https://github.com/nanocosmos/nanoplayer-vuejs-sample -
WordPress: add a Custom HTML block with the script, the config and the setup call. Wrap
playerDivin a sized container, otherwise the player isn't visible:<div style="width: 480px; height: 360px; overflow: hidden; position: relative;"><div id="playerDiv"></div></div>
Embed with the hosted iframe
The hosted embed page (version 2.0.0) runs the latest nanoStream Player 5.x. You configure it entirely through URL parameters.
<iframe
src="https://demo.nanocosmos.de/nanoplayer/embed/2.0.0/nanoplayer.html?group.id=<STREAM_GROUP_ID>"
frameborder="0" allowfullscreen width="1280" height="720">
</iframe>
The src must include a source parameter (group.id or entry.rtmp.streamname). Without one, the player loads but has nothing to play. Keep allowfullscreen if viewers should be able to go fullscreen.
URL parameters
Parameters map to the player config in dot notation. Leave out the source. prefix; keep every other object name (playback., style., …).
| Parameter | Example | Notes |
|---|---|---|
group.id | group.id=<STREAM_GROUP_ID> | Stream group source |
group.security.jwtoken | group.security.jwtoken=<YOUR_JWT> | Token for a secure group |
group.startQuality | group.startQuality=medium | Start rendition for a group |
entry.rtmp.streamname | entry.rtmp.streamname=XXXXX-YYYYY | Single stream; entry2., entry3. for more entries |
entry.info.bitrate | entry.info.bitrate=1500 | Bitrate (kbit/s) for entry-based ABR |
startIndex | startIndex=2 | Start entry for entry-based ABR |
options.adaption.rule | options.adaption.rule=deviationOfMean2 | ABR switching rule for entries |
defaults.service | defaults.service=bintu | Use nanocosmos defaults |
playback.autoplay, playback.automute, playback.muted | playback.autoplay=true | |
playback.faststart, playback.metadata | playback.metadata=true | |
playback.latencyControlMode | playback.latencyControlMode=balancedadaptive | classic, balancedadaptive, fastadaptive |
playback.timeouts.buffering | playback.timeouts.buffering=20 | Seconds |
style.fullScreenControl, style.displayMutedAutoplay | style.fullScreenControl=true | |
style.backgroundColor, style.poster | style.backgroundColor=black | Poster is an image URL |
tweaks.buffer.* | tweaks.buffer.limit=1.7 | Pass the complete set |
metrics.accountId, metrics.accountKey | Player metrics | |
title | title=My%20Event | Page title of the embed |
Booleans must be the strings true or false. Since embed 2.0.0, 1 and 0 are not converted. If you used playback.metadata=1 with embed 1.x, change it to playback.metadata=true.
Example with ABR over three entries and muted autoplay:
https://demo.nanocosmos.de/nanoplayer/embed/2.0.0/nanoplayer.html?entry.rtmp.streamname=XXXXX-AAAAA&entry.info.bitrate=1500&entry2.rtmp.streamname=XXXXX-BBBBB&entry2.info.bitrate=800&entry3.rtmp.streamname=XXXXX-CCCCC&entry3.info.bitrate=200&options.adaption.rule=deviationOfMean2&startIndex=2&playback.autoplay=true&playback.automute=true
Tokens restricted to a domain (referrer binding) don't work with the hosted iframe, because playback requests come from the embed page's domain, not yours. Use the JavaScript API on your own page instead.
Host your own player page in an iframe
-
Build a page on your domain with the JavaScript API, as above.
-
Embed that page on the distributing page:
<iframe id="ifvideo" width="640" height="480" scrolling="no" frameborder="0" allowfullscreensrc="https://yourdomain.com/playerpage.html"></iframe>
Test with the demo player
Before embedding, check that the stream plays in the hosted demo player:
https://demo.nanocosmos.de/nanoplayer/release/nanoplayer.html?group.id=<STREAM_GROUP_ID>
For a token-protected stream, the token parameter must match the source form: with group.id= use group.security.jwtoken=<YOUR_JWT>. With any other prefix the player ignores the token and playback fails, even though the token is valid.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
Nothing appears, NanoPlayer is not defined | The script didn't load. Check the URL and that the <script> tag is closed. |
| Player stays black or shows "connecting" | The stream isn't live, or the ID or name is wrong. Watch onError for codes 2001 and 2002, and onPause with reason streamnotfound. See Events & error codes. |
| No autoplay with sound on mobile | Browsers block autoplay with sound. Keep automute: true so the player starts muted. |
| Secure stream doesn't play | Missing, expired or mis-scoped token, or the token param doesn't match the source form. See Playback tokens. |
| Player invisible in WordPress | Wrap playerDiv in a sized container. |
Next steps
- Player configuration reference
- Player features
- Playback tokens
- Multi-Player: several streams on one page
Try it in the Builder Hub: start an Instant Live Stream and watch it in the nanoStream Player in seconds. See the Builder Hub guide. Start for Free