Skip to content

Commit

Permalink
Removed a test and added a new test to ensure that multiple play even…
Browse files Browse the repository at this point in the history
…ts don't speed up the playback monitor check
  • Loading branch information
evanfarina committed Mar 3, 2021
1 parent d923046 commit 1aec412
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/playback-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export default class PlaybackWatcher {
this.tech_.off('waiting', waitingHandler);
this.tech_.off(timerCancelEvents, cancelTimerHandler);
this.tech_.off('canplay', canPlayHandler);
this.tech_.off('play', playHandler);

loaderTypes.forEach((type) => {
mpc[`${type}SegmentLoader_`].off('appendsdone', loaderChecks[type].updateend);
Expand Down
20 changes: 10 additions & 10 deletions test/playback-watcher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ QUnit.module('PlaybackWatcher', {
}
});

QUnit.test('skips over gap at beginning of stream if player is paused', function(assert) {
QUnit.test('skips over gap at beginning of stream if played before content is buffered', function(assert) {
let vhsGapSkipEvents = 0;
let hlsGapSkipEvents = 0;

this.player.autoplay(true);

this.player.tech_.on('usage', (event) => {
if (event.name === 'vhs-gap-skip') {
vhsGapSkipEvents++;
Expand Down Expand Up @@ -87,13 +85,10 @@ QUnit.test('skips over gap at beginning of stream if player is paused', function
);
});

QUnit.test('Does NOT skip over gap at beginning of stream if player is playing', function(assert) {
QUnit.test('Multiple play events do not cause the gap-skipping logic to be called sooner than expected', function(assert) {
let vhsGapSkipEvents = 0;
let hlsGapSkipEvents = 0;

this.player.autoplay(true);
this.player.tech_.paused = () => false;

this.player.tech_.on('usage', (event) => {
if (event.name === 'vhs-gap-skip') {
vhsGapSkipEvents++;
Expand All @@ -119,17 +114,22 @@ QUnit.test('Does NOT skip over gap at beginning of stream if player is playing',
// create a buffer with a gap of 2 seconds at beginning of stream
this.player.tech_.buffered = () => videojs.createTimeRanges([[2, 10]]);
// Playback watcher loop runs on a 250ms clock and needs run 6 consecutive stall checks before skipping the gap
this.clock.tick(250 * 6);
// Start with three consecutive playback checks
this.clock.tick(250 * 3);
// and then simulate the playback monitor being called 'manually' by a new play event
this.player.tech_.trigger('play');
// Simulate remaining time
this.clock.tick(250 * 2);
// Need to wait for the duration of the gap
this.clock.tick(2000);

assert.equal(vhsGapSkipEvents, 0, 'there is no skipped gap');
assert.equal(hlsGapSkipEvents, 0, 'there is no skipped gap');

// check that player jumped the gap
// check that player did not skip the gap
assert.equal(
Math.round(this.player.currentTime()),
0, 'Player did not seek over gap'
0, 'Player seeked over gap after timer'
);
});

Expand Down

0 comments on commit 1aec412

Please sign in to comment.