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

feat: trigger ended when stalling near end of video #105

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
8 changes: 8 additions & 0 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const defaults = {
timeout: 45 * 1000,
dismiss: defaultDismiss,
progressDisabled: false,
durationTolerance: 0.5,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is .5 seconds too high of a duration tolerance? Maybe it isn't, or doesn't matter too much, but I know I've even seen HLS segments where the last one is really short (within that tolerance). Again, it might not matter, and 1 second seems a reasonable amount of time for .5 seconds, but I just wanted to make sure we don't want to start with either a too high of a tolerance and/or too low of a wait time.

Copy link
Contributor Author

@forbesjo forbesjo Jun 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.5 is an arbitrary low number. For reference here's an issue with a source that stops 0.6 near the end. Again this would only kick in if the player is starting to stall.

shaka-project/shaka-player#913

errors: {
'1': {
type: 'MEDIA_ERR_ABORTED',
Expand Down Expand Up @@ -101,6 +102,13 @@ const initPlugin = function(player, options) {
return;
}

// if the player has started to stall and
// playback is almost at the end just end playback
if ((player.duration() - player.currentTime()) < options.durationTolerance) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a rare case, but I believe it is possible that in HLS, if we start the video the manifest hasn't downloaded, and we can't get a source buffer (or it takes a long time for some reason), this will trigger ended after we get waiting (since duration will return as 0 and current time as 0). Although it is rare, and we can probably resolve it, we may just want to check that duration is > 0 to be safe. I believe the standard for media sources is NaN, which should be fine, but, since different technologies may follow different behaviors when returning a non-existent duration, we may want to have the extra check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, adding the check. I'll also undo the updates to the tests.

player.trigger('ended');
return;
}

isStalling = true;
player.addClass('vjs-waiting');
}, 1000);
Expand Down
32 changes: 32 additions & 0 deletions test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ QUnit.test('play() without a src is an error', function(assert) {
QUnit.test('no progress for 1 second shows the loading spinner', function(assert) {
this.player.src(sources);
this.player.trigger('play');
this.player.currentTime = function() {
return 10;
};
this.player.duration = function() {
return 20;
};
this.clock.tick(1 * 1000);

assert.ok(
Expand All @@ -105,9 +111,35 @@ QUnit.test('no progress for 1 second shows the loading spinner', function(assert
);
});

QUnit.test('no progress for 1 near end of video triggers ended', function(assert) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 second

let ended = 0;

this.player.on('ended', function() {
ended++;
});

this.player.src(sources);
this.player.trigger('play');
this.player.currentTime = function() {
return 1;
};
this.player.duration = function() {
return 1.2;
};
this.clock.tick(1 * 1000);

assert.strictEqual(ended, 1, 'has ended');
});

QUnit.test('progress events while playing reset the spinner', function(assert) {
this.player.src(sources);
this.player.trigger('play');
this.player.currentTime = function() {
return 10;
};
this.player.duration = function() {
return 20;
};
// stalled for awhile
this.clock.tick(44 * 1000);
assert.ok(
Expand Down