Skip to content

Commit

Permalink
feat: support fastSeek during scrubbing if available (#6525)
Browse files Browse the repository at this point in the history
This will allow us to use iframe playlists on HLS on Safari browsers and eventually, add support in VHS.
  • Loading branch information
gkatsev committed Apr 22, 2020
1 parent 808d818 commit 8c66c58
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/js/player.js
Expand Up @@ -2432,6 +2432,7 @@ class Player extends Component {
return this.scrubbing_;
}
this.scrubbing_ = !!isScrubbing;
this.techCall_('setScrubbing', this.scrubbing_);

if (isScrubbing) {
this.addClass('vjs-scrubbing');
Expand Down
10 changes: 9 additions & 1 deletion src/js/tech/html5.js
Expand Up @@ -520,6 +520,10 @@ class Html5 extends Tech {
});
}

setScrubbing(isScrubbing) {
this.isScrubbing_ = isScrubbing;
}

/**
* Set current time for the `HTML5` tech.
*
Expand All @@ -528,7 +532,11 @@ class Html5 extends Tech {
*/
setCurrentTime(seconds) {
try {
this.el_.currentTime = seconds;
if (this.isScrubbing_ && this.el_.fastSeek) {
this.el_.fastSeek(seconds);
} else {
this.el_.currentTime = seconds;
}
} catch (e) {
log(e, 'Video is not ready. (Video.js)');
// this.warning(VideoJS.warnings.videoNotReady);
Expand Down
17 changes: 17 additions & 0 deletions test/unit/player.test.js
Expand Up @@ -1241,6 +1241,23 @@ QUnit.test('should add an audio player region if an audio el is used', function(
player.dispose();
});

QUnit.test('should setScrubbing when seeking or not seeking', function(assert) {
const player = TestHelpers.makePlayer();
let isScrubbing;

player.tech_.setScrubbing = (_isScrubbing) => {
isScrubbing = _isScrubbing;
};

assert.equal(player.scrubbing(), false, 'player is not scrubbing');

player.scrubbing(true);
assert.ok(isScrubbing, "tech's setScrubbing was called with true");

player.scrubbing(false);
assert.notOk(isScrubbing, "tech's setScrubbing was called with false");
});

QUnit.test('should not be scrubbing while not seeking', function(assert) {
const player = TestHelpers.makePlayer();

Expand Down
33 changes: 33 additions & 0 deletions test/unit/tech/html5.test.js
Expand Up @@ -5,6 +5,7 @@ let tech;
import Html5 from '../../../src/js/tech/html5.js';
import * as browser from '../../../src/js/utils/browser.js';
import document from 'global/document';
import sinon from 'sinon';

QUnit.module('HTML5', {
beforeEach(assert) {
Expand Down Expand Up @@ -50,6 +51,38 @@ QUnit.module('HTML5', {
}
});

QUnit.test('if setScrubbing is true and fastSeek is available, use it', function(assert) {
Object.defineProperty(tech.el(), 'currentTime', {
get: () => {},
set: () => {},

writeable: true,
enumerable: false,
configurable: true
});

const currentTimeSpy = sinon.spy(tech.el(), 'currentTime', ['set']);

tech.setCurrentTime(5);
assert.ok(currentTimeSpy.set.called, 'currentTime setter was called');
assert.ok(currentTimeSpy.set.calledWith(5), 'currentTime setter was called with 5');

tech.setScrubbing(true);

// when scrubbing is set but fastSeek isn't available, currentTime should still be called
tech.el().fastSeek = null;
tech.setCurrentTime(10);
assert.ok(currentTimeSpy.set.called, 'currentTime setter was called');
assert.ok(currentTimeSpy.set.calledWith(10), 'currentTime setter was called with 10');

const fastSeekSpy = tech.el().fastSeek = sinon.spy();

tech.setCurrentTime(15);
assert.ok(currentTimeSpy.set.calledTwice, 'currentTime setter was only called twice and not a 3rd time for fastSeek');
assert.ok(fastSeekSpy.called, 'fastSeek called');
assert.ok(fastSeekSpy.calledWith(15), 'fastSeek called with 15');
});

QUnit.test('should be able to set playsinline attribute', function(assert) {
assert.expect(2);

Expand Down
1 change: 1 addition & 0 deletions test/unit/tech/tech-faker.js
Expand Up @@ -97,6 +97,7 @@ class TechFaker extends Tech {
seeking() {
return false;
}
setScrubbing() {}
fakeSourceset() {
this.el_.src = this.options_.sourceset;
this.el_.setAttribute('src', this.options_.sourceset);
Expand Down

0 comments on commit 8c66c58

Please sign in to comment.