Buffered segments are now shown on the progress bar
This commit is contained in:
parent
0aac98ddc2
commit
13a5d4059a
@ -646,6 +646,7 @@
|
||||
this.setActivePlaylistItem();
|
||||
this.autoBlurControls();
|
||||
this.initProgressTracking();
|
||||
this.initBuffer();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -702,6 +703,48 @@
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize display of buffered segments in the progress bar.
|
||||
*/
|
||||
initBuffer() {
|
||||
const color = window.getComputedStyle(this._root)
|
||||
.getPropertyValue('--foreground');
|
||||
const buffer = this._progressBuffer;
|
||||
const control = this._controlSource;
|
||||
var needsUpdate = false;
|
||||
|
||||
function paintBuffer() {
|
||||
if(needsUpdate) {
|
||||
buffer.width = buffer.clientWidth;
|
||||
buffer.height = buffer.clientHeight;
|
||||
|
||||
const context = buffer.getContext('2d');
|
||||
context.clearRect(0, 0, buffer.width, buffer.height);
|
||||
context.fillStyle = color;
|
||||
context.strokeStyle = color;
|
||||
|
||||
const inc = buffer.width / control.duration;
|
||||
const buffered = control.buffered;
|
||||
for(let i = 0; i < buffered.length; i++) {
|
||||
const start = buffered.start(i) * inc;
|
||||
const end = buffered.end(i) * inc;
|
||||
const width = end - start;
|
||||
context.fillRect(start, 0, width, buffer.height);
|
||||
}
|
||||
needsUpdate = false;
|
||||
}
|
||||
requestAnimationFrame(paintBuffer);
|
||||
}
|
||||
|
||||
function flagUpdate(event) {
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
||||
control.addEventListener('progress', flagUpdate);
|
||||
window.addEventListener('resize', flagUpdate);
|
||||
window.requestAnimationFrame(paintBuffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the playlist to reflect which item is playing
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user