diff --git a/src/plugin.js b/src/plugin.js index a739d89..090cf05 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -78,7 +78,8 @@ const offset = function(options) { duration: Player.prototype.duration, currentTime: Player.prototype.currentTime, bufferedPercent: Player.prototype.bufferedPercent, - remainingTime: Player.prototype.remainingTime + remainingTime: Player.prototype.remainingTime, + buffered: Player.prototype.buffered }; Player.prototype.duration = function() { @@ -116,6 +117,20 @@ const offset = function(options) { } return this.duration(); }; + + Player.prototype.buffered = function() { + const buff = Player.__super__.buffered.call(this); + const ranges = []; + + for (let i = 0; i < buff.length; i++) { + ranges[i] = [ + Math.max(0, buff.start(i) - this._offsetStart), + Math.min(Math.max(0, buff.end(i) - this._offsetStart), this.duration()) + ]; + } + + return videojs.createTimeRanges(ranges); + }; } this.ready(() => { diff --git a/test/plugin.test.js b/test/plugin.test.js index 108fff1..c2061d1 100644 --- a/test/plugin.test.js +++ b/test/plugin.test.js @@ -38,7 +38,7 @@ QUnit.module('videojs-offset', { }); QUnit.test('registers itself with video.js', function(assert) { - assert.expect(2); + assert.expect(5); assert.strictEqual( typeof Player.prototype.offset, @@ -58,4 +58,10 @@ QUnit.test('registers itself with video.js', function(assert) { this.player.duration() === 290, 'the plugin alters video duration adjusting to start|end options' ); + + const buffered = this.player.buffered(); + + assert.ok(buffered.length, 'buffer has length'); + assert.ok(buffered.start, 'buffer has start'); + assert.ok(buffered.end, 'buffer has end'); });