-
Notifications
You must be signed in to change notification settings - Fork 29
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ const defaults = { | |
timeout: 45 * 1000, | ||
dismiss: defaultDismiss, | ||
progressDisabled: false, | ||
durationTolerance: 0.5, | ||
errors: { | ||
'1': { | ||
type: 'MEDIA_ERR_ABORTED', | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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