Skip to content

Commit

Permalink
Add an example that shows how to use the new settigns module
Browse files Browse the repository at this point in the history
  • Loading branch information
jeoliva committed Jun 18, 2019
1 parent d2c4a5e commit ecfeeec
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 8 deletions.
2 changes: 0 additions & 2 deletions samples/advanced/monitoring.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
clearInterval(bitrateCalculator);
});

// player.on(dashjs.MediaPlayer.events["BUFFER_LEVEL_STATE_CHANGED"], showEvent);

var eventPoller = setInterval(function() {
var streamInfo = player.getActiveStream().getStreamInfo();
var dashMetrics = player.getDashMetrics();
Expand Down
136 changes: 136 additions & 0 deletions samples/advanced/settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Dash.js settings example</title>

<script src="../../dist/dash.all.debug.js"></script>
<!--dash.all.min.js should be used in production over dash.all.debug.js
Debug files are not compressed or obfuscated making the file size much larger compared with dash.all.min.js-->
<!--<script src="../../dist/dash.all.min.js"></script>-->

<script>
var player;
function init() {
var video,
url = "https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd";

video = document.querySelector("video");
player = dashjs.MediaPlayer().create();
player.initialize(video, url, true);

applySettings()

player.on(dashjs.MediaPlayer.events["PLAYBACK_ENDED"], function() {
clearInterval(eventPoller);
});

var eventPoller = setInterval(function() {
var streamInfo = player.getActiveStream().getStreamInfo();
var dashMetrics = player.getDashMetrics();
var dashAdapter = player.getDashAdapter();

if (dashMetrics && streamInfo) {
const periodIdx = streamInfo.index;
var repSwitch = dashMetrics.getCurrentRepresentationSwitch('video', true);
var bufferLevel = dashMetrics.getCurrentBufferLevel('video', true);
var bitrate = repSwitch ? Math.round(dashAdapter.getBandwidthForRepresentation(repSwitch.to, periodIdx) / 1000) : NaN;
document.getElementById('currentBufferLevel').innerText = bufferLevel + " secs";
document.getElementById('reportedBitrate').innerText = bitrate + " Kbps";
}
}, 1000);
}
</script>

<script class="code">
function applySettings() {
var stableBuffer = parseInt(document.getElementById('stableBuffer').value, 10);
var bufferAtTopQuality = parseInt(document.getElementById('topQualityBuffer').value, 10);
var minBitrate = parseInt(document.getElementById('minBitrate').value, 10);
var maxBitrate = parseInt(document.getElementById('maxBitrate').value, 10);
var limitByPortal = document.getElementById('limitByPortal').checked;

player.updateSettings({
'streaming': {
'stableBufferTime': stableBuffer,
'bufferTimeAtTopQualityLongForm': bufferAtTopQuality,
'abr': {
'minBitrate': {
'video': minBitrate
},
'maxBitrate': {
'video': maxBitrate
},
'limitBitrateByPortal': limitByPortal
}
}
})
}
</script>

<style>
video {
width: 70%;
}

#container {
display: inline-block;
}

fieldset {
width: 70%;
}
fieldset > div {
margin-top: 20px;
}

.description {
font-size: 0.9em;
color: #888888;
}

</style>
</head>
<body>
<div id="container">
<div class="video-container">
<video data-dashjs-player autoplay controls="true">
</video>
</div>
<fieldset>
<legend>Configuration parameters</legend>
<div>
Max stable buffer (seconds): <input type="number" id="stableBuffer" value="20"> (Current Buffer: <span id="currentBufferLevel")>0</span> seconds)
<div class="description">The time that the internal buffer target will be set to post startup/seeks (NOT top quality).</div>
</div>
<div>
Buffer lenght at top quality (seconds): <input type="number" id="topQualityBuffer" value="20">
<div class="description">The time that the internal buffer target will be set to once playing the top quality.</div>
</div>
<div>
Max selectable bitrate (Kbps): <input type="number" id="maxBitrate" value="5000"> (Downloading bitrate: <span id="reportedBitrate")>0</span>)
<div class="description">The maximum bitrate selectable by the ABR algorithms will choose. Use -1 for no limit.</div>
</div>
<div>
Min selectable bitrate (Kbps): <input type="number" id="minBitrate" value="-1">
<div class="description">The minimum bitrate that the ABR algorithms will choose. Use -1 for no limit.</div>
</div>
<div>
Limit Bitrate By Portal Size: <input type="checkbox" id="limitByPortal">
<div class="description">If true, the size of the video portal will limit the max chosen video resolution.</div>
</div>
<div>
<button onclick="applySettings()">Apply changes</button>
</div>
</fieldset>
</div>
<script>
document.addEventListener("DOMContentLoaded", function () {
init();
});
</script>
<script src="../highlighter.js"></script>
</body>
</html>


18 changes: 12 additions & 6 deletions samples/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,27 @@
},
{
"section": "Advanced",
"samples": [{
"samples": [
{
"title": "Monitoring the stream",
"description": "This example shows how to monitor metrics of the streams played by dash.js.",
"href": "advanced/monitoring.html"
},
{
"title": "Dash.js settings",
"description": "This example shows how to deal with dash.js settings.",
"href": "advanced/settings.html"
},
{
"title": "Listening to SCTE-EMSG Events",
"description": "Example showing how to listen to SCTE EMSG events raised by dash.js.",
"href": "advanced/listening-to-SCTE-EMSG-events.html"
},
{
"title": "Autoplay Browser policy",
"description": "This sample shows how to deal with autoplay browsers policy. It uses an event listener to detect when auto playback is interrupted by the browser and how to recover from this situation muting audio.",
"href": "advanced/auto-play-browser-policy.html"
},
{
"title": "Custom ABR Rules",
"description": "Example showing how to create and define custom ABR rules in dash.js.",
Expand All @@ -202,11 +213,6 @@
"title": "Extending Dash.js",
"description": "This sample shows how to use dash.js extend mechanism to add custom HTTP headers and modify URL's of the requests done by the player.",
"href": "advanced/extend.html"
},
{
"title": "Autoplay Browser policy",
"description": "This sample shows how to deal with autoplay browsers policy. It uses an event listener to detect when auto playback is interrupted by the browser and how to recover from this situation muting audio." ,
"href": "advanced/auto-play-browser-policy.html"
}
]
}
Expand Down

0 comments on commit ecfeeec

Please sign in to comment.