Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buffer level bar to control bar #2419

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 34 additions & 9 deletions contrib/akamai/controlbar/ControlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
trackSwitchBtn,
seekbar,
seekbarPlay,
seekbarBuffer,
muteBtn,
volumebar,
fullscreenBtn,
Expand Down Expand Up @@ -76,6 +77,7 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
trackSwitchBtn = document.getElementById(getControlId("trackSwitchBtn"));
seekbar = document.getElementById(getControlId("seekbar"));
seekbarPlay = document.getElementById(getControlId("seekbar-play"));
seekbarBuffer = document.getElementById(getControlId("seekbar-buffer"));
muteBtn = document.getElementById(getControlId("muteBtn"));
volumebar = document.getElementById(getControlId("volumebar"));
fullscreenBtn = document.getElementById(getControlId("fullscreenBtn"));
Expand Down Expand Up @@ -138,9 +140,31 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
if (!seeking) {
setTime(displayUTCTimeCodes ? player.timeAsUTC() : player.time());

if (!seekbarPlay) return ;
seekbarPlay.style.width = (player.time() / player.duration() * 100) + '%';
if (seekbarPlay) {
seekbarPlay.style.width = (player.time() / player.duration() * 100) + '%';
}

if (seekbarBuffer) {
seekbarBuffer.style.width = ((player.time() + getBufferLevel()) / player.duration() * 100) + '%';
}

}
},

getBufferLevel = function () {
var videoMetrics = player.getMetricsFor('video');
var audioMetrics = player.getMetricsFor('audio');
var dashMetrics = player.getDashMetrics();
var bufferLevel = 0;

if (dashMetrics) {
if (videoMetrics) {
bufferLevel = dashMetrics.getCurrentBufferLevel(videoMetrics);
} else if (audioMetrics) {
bufferLevel = dashMetrics.getCurrentBufferLevel(audioMetrics);
}
}
return bufferLevel;
},

//************************************************************************************
Expand Down Expand Up @@ -186,9 +210,8 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
// ************************************************************************************

calculateTimeByEvent = function (event) {
var seekbarWidth = parseFloat(window.getComputedStyle(seekbar).width);
var seekbarRect = seekbar.getBoundingClientRect();
return Math.floor(player.duration() * (event.clientX - seekbarRect.left) / seekbarWidth);
return Math.floor(player.duration() * (event.clientX - seekbarRect.left) / seekbarRect.width);
},

onSeeking = function (event) {
Expand Down Expand Up @@ -216,9 +239,9 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {

onSeekBarMouseMoveOut(event);

if (!seekbarPlay) return ;
seekbarPlay.style.width = (mouseTime / player.duration() * 100) + '%';

if (seekbarPlay) {
seekbarPlay.style.width = (mouseTime / player.duration() * 100) + '%';
}
},

onSeekBarMouseMove = function (event) {
Expand Down Expand Up @@ -768,7 +791,6 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
player.on(dashjs.MediaPlayer.events.PLAYBACK_STARTED, onPlayStart, this);
player.on(dashjs.MediaPlayer.events.PLAYBACK_PAUSED, onPlaybackPaused, this);
player.on(dashjs.MediaPlayer.events.PLAYBACK_TIME_UPDATED, onPlayTimeUpdate, this);
player.on(dashjs.MediaPlayer.events.PLAYBACK_SEEKED, onSeeked, this);
player.on(dashjs.MediaPlayer.events.TEXT_TRACKS_ADDED, onTracksAdded, this);
player.on(dashjs.MediaPlayer.events.STREAM_INITIALIZED, onStreamInitialized, this);
player.on(dashjs.MediaPlayer.events.STREAM_TEARDOWN_COMPLETE, onStreamTeardownComplete, this);
Expand Down Expand Up @@ -835,6 +857,10 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
if (seekbarPlay) {
seekbarPlay.style.width = '0%';
}

if (seekbarBuffer) {
seekbarBuffer.style.width = '0%';
}
},

destroy: function () {
Expand All @@ -855,7 +881,6 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
player.off(dashjs.MediaPlayer.events.PLAYBACK_STARTED, onPlayStart, this);
player.off(dashjs.MediaPlayer.events.PLAYBACK_PAUSED, onPlaybackPaused, this);
player.off(dashjs.MediaPlayer.events.PLAYBACK_TIME_UPDATED, onPlayTimeUpdate, this);
player.off(dashjs.MediaPlayer.events.PLAYBACK_SEEKED, onSeeked, this);
player.off(dashjs.MediaPlayer.events.TEXT_TRACKS_ADDED, onTracksAdded, this);
player.off(dashjs.MediaPlayer.events.STREAM_INITIALIZED, onStreamInitialized, this);
player.off(dashjs.MediaPlayer.events.STREAM_TEARDOWN_COMPLETE, onStreamTeardownComplete, this);
Expand Down
16 changes: 16 additions & 0 deletions contrib/akamai/controlbar/controlbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
}

.seekContainer {
display: flex;
overflow: auto;
overflow-y: hidden;
overflow-x: hidden;
Expand Down Expand Up @@ -283,10 +284,25 @@ input[type="range"]::-ms-thumb {
width: 100%;
height: 7px;
margin-top: 16px;
background: #dfdfdfbb;
position: relative;
}

.seekbar-buffer {
z-index: 100;
position: absolute;
left: 0px;
top: 0px;
width: 0%;
height: 7px;
background: lightgray;
}

.seekbar-play {
z-index: 1000;
position: absolute;
left: 0px;
top: 0px;
width: 0%;
height: 7px;
background: rgb(0, 150, 215);
Expand Down
1 change: 1 addition & 0 deletions contrib/akamai/controlbar/snippet.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<div class="seekContainer">
<div id="seekbar" class="seekbar seekbar-complete">
<div id="seekbar-play" class="seekbar seekbar-play"></div>
<div id="seekbar-buffer" class="seekbar seekbar-buffer"></div>
</div>
</div>
<div id="thumbnail-container" class="thumbnail-container">
Expand Down
1 change: 0 additions & 1 deletion samples/chromecast/receiver/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function ReceiverController($scope) {
pendingValue,
numBitratesValue,
bufferLengthValue = 0,
point,
lastFragmentDuration,
lastFragmentDownloadTime,
droppedFramesValue = 0;
Expand Down
1 change: 1 addition & 0 deletions samples/dash-if-reference-player/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
<div class="seekContainer">
<div id="seekbar" class="seekbar seekbar-complete">
<div id="seekbar-play" class="seekbar seekbar-play"></div>
<div id="seekbar-buffer" class="seekbar seekbar-buffer"></div>
</div>
</div>
<div id="thumbnail-container" class="thumbnail-container">
Expand Down