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

Fix LoadProgressBar position #28

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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(() => {
Expand Down
8 changes: 7 additions & 1 deletion test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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');
});