1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-29 02:57:21 +02:00

Added support for multiple time ranges in the load progress bar

closes #1253

Display a true load progress (with accounting all buffered regions)

Add played property for player

Correctly display played regions in progress-bar

Support #played in MediaFaker so tests would pass

Remove play-progress regions but add some opacity to play-progress

Remove opacity

Revert "Add played property for player"

This reverts commit 6d8bf982c2.

Fixed an issue where a load progress of NaN was throwing an error

Reverted some remaining `played` changes

Updated the progress bar to encapsulate time ranges

In the previous commit the progress bar was broken up into timeranges.
This had the effect of looking broken, so now the progress bar covers
all time ranges, and the time ranges a subtley different in color
from the progress bar.
This commit is contained in:
brainopia 2014-05-28 11:04:55 +04:00 committed by Steve Heffernan
parent 6921b552ef
commit b2fbc8059b
4 changed files with 100 additions and 25 deletions

View File

@ -396,7 +396,8 @@ fonts to show/hide properly.
/* Progress Bars */
.vjs-default-skin .vjs-progress-holder .vjs-play-progress,
.vjs-default-skin .vjs-progress-holder .vjs-load-progress {
.vjs-default-skin .vjs-progress-holder .vjs-load-progress,
.vjs-default-skin .vjs-progress-holder .vjs-load-progress div {
position: absolute;
display: block;
height: 100%;
@ -424,7 +425,14 @@ fonts to show/hide properly.
}
.vjs-default-skin .vjs-load-progress {
background: rgb(100, 100, 100) /* IE8- Fallback */;
background: rgba(255, 255, 255, 0.4);
background: rgba(255, 255, 255, 0.2);
}
/* there are child elements of the load progress bar that represent the
specific time ranges that have been buffered */
.vjs-default-skin .vjs-load-progress div {
background: rgb(120, 120, 120) /* IE8- Fallback */;
background: rgba(255, 255, 255, 0.1);
}
.vjs-default-skin .vjs-seek-handle {

View File

@ -107,7 +107,6 @@ vjs.SeekBar.prototype.stepBack = function(){
this.player_.currentTime(this.player_.currentTime() - 5); // more quickly rewind for keyboard-only users
};
/**
* Shows load progress
*
@ -125,15 +124,45 @@ vjs.LoadProgressBar = vjs.Component.extend({
vjs.LoadProgressBar.prototype.createEl = function(){
return vjs.Component.prototype.createEl.call(this, 'div', {
className: 'vjs-load-progress',
innerHTML: '<span class="vjs-control-text">Loaded: 0%</span>'
className: 'vjs-load-progress'
});
};
vjs.LoadProgressBar.prototype.update = function(){
if (this.el_.style) { this.el_.style.width = vjs.round(this.player_.bufferedPercent() * 100, 2) + '%'; }
};
var i, start, end, part,
buffered = this.player_.buffered(),
duration = this.player_.duration(),
bufferedEnd = this.player_.bufferedEnd(),
children = this.el_.children,
// get the percent width of a time compared to the total end
percentify = function (time, end){
var percent = (time / end) || 0; // no NaN
return (percent * 100) + '%';
};
// update the width of the progress bar
this.el_.style.width = percentify(bufferedEnd, duration);
// add child elements to represent the individual buffered time ranges
for (i = 0; i < buffered.length; i++) {
start = buffered.start(i),
end = buffered.end(i),
part = children[i];
if (!part) {
part = this.el_.appendChild(vjs.createEl())
};
// set the percent based on the width of the progress bar (bufferedEnd)
part.style.left = percentify(start, bufferedEnd);
part.style.width = percentify(end - start, bufferedEnd);
};
// remove unused buffered range elements
for (i = children.length; i > buffered.length; i--) {
this.el_.removeChild(children[i-1]);
}
};
/**
* Shows play progress

View File

@ -355,13 +355,17 @@ vjs.Player.prototype.trackProgress = function(){
this.progressInterval = setInterval(vjs.bind(this, function(){
// Don't trigger unless buffered amount is greater than last time
// log(this.cache_.bufferEnd, this.buffered().end(0), this.duration())
/* TODO: update for multiple buffered regions */
if (this.cache_.bufferEnd < this.buffered().end(0)) {
var bufferedPercent = this.bufferedPercent();
if (this.cache_.bufferedPercent != bufferedPercent) {
this.trigger('progress');
} else if (this.bufferedPercent() == 1) {
}
this.cache_.bufferedPercent = bufferedPercent;
if (bufferedPercent == 1) {
this.stopTrackingProgress();
this.trigger('progress'); // Last update
}
}), 500);
};
@ -748,7 +752,6 @@ vjs.Player.prototype.remainingTime = function(){
// http://dev.w3.org/html5/spec/video.html#dom-media-buffered
// Buffered returns a timerange object.
// Kind of like an array of portions of the video that have been downloaded.
// So far no browsers return more than one range (portion)
/**
* Get a TimeRange object with the times of the video that have been downloaded
@ -771,19 +774,13 @@ vjs.Player.prototype.remainingTime = function(){
* @return {Object} A mock TimeRange object (following HTML spec)
*/
vjs.Player.prototype.buffered = function(){
var buffered = this.techGet('buffered'),
start = 0,
buflast = buffered.length - 1,
// Default end to 0 and store in values
end = this.cache_.bufferEnd = this.cache_.bufferEnd || 0;
var buffered = this.techGet('buffered');
if (buffered && buflast >= 0 && buffered.end(buflast) !== end) {
end = buffered.end(buflast);
// Storing values allows them be overridden by setBufferedFromProgress
this.cache_.bufferEnd = end;
if (!buffered || !buffered.length) {
buffered = vjs.createTimeRange(0,0);
}
return vjs.createTimeRange(start, end);
return buffered;
};
/**
@ -797,7 +794,46 @@ vjs.Player.prototype.buffered = function(){
* @return {Number} A decimal between 0 and 1 representing the percent
*/
vjs.Player.prototype.bufferedPercent = function(){
return (this.duration()) ? this.buffered().end(0) / this.duration() : 0;
var duration = this.duration(),
buffered = this.buffered(),
bufferedDuration = 0,
start, end;
if (!duration) {
return 0;
}
for (var i=0; i<buffered.length; i++){
start = buffered.start(i);
end = buffered.end(i);
// buffered end can be bigger than duration by a very small fraction
if (end > duration) {
end = duration;
}
bufferedDuration += end - start;
}
return bufferedDuration / duration;
};
/**
* Get the ending time of the last buffered time range
*
* This is used in the progress bar to encapsulate all time ranges.
* @return {Number} The end of the last buffered time range
*/
vjs.Player.prototype.bufferedEnd = function(){
var buffered = this.buffered(),
duration = this.duration(),
end = buffered.end(buffered.length-1);
if (end > duration) {
end = duration;
}
return end;
};
/**

View File

@ -117,7 +117,9 @@ vjs.Slider.prototype.update = function(){
}
// Set the new bar width
bar.el().style.width = vjs.round(barProgress * 100, 2) + '%';
if (bar) {
bar.el().style.width = vjs.round(barProgress * 100, 2) + '%';
}
};
vjs.Slider.prototype.calculateDistance = function(event){