-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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: Seek bar smooth seeking #8287
feat: Seek bar smooth seeking #8287
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8287 +/- ##
==========================================
+ Coverage 82.71% 82.77% +0.05%
==========================================
Files 113 113
Lines 7592 7600 +8
Branches 1826 1829 +3
==========================================
+ Hits 6280 6291 +11
+ Misses 1312 1309 -3 ☔ View full report in Codecov by Sentry. |
Observation
|
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.
Looks good and is more in line with other players' behaviour. Thanks!. One observation is that you no longer have an indication of where you were in the video when you started seeking, if that matters.
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.
At first, I was worried about this change because the original reason we didn't update this is that internally we are still seeking directly and basically relying on it for the preview and we were worried about the potential jump it a seek failed and the mismatch between the preview and the seek bar. However, at least on desktop, it seems to be working well enough and I actually think this behavior feels a bit better. Keeping it as an option (and perhaps enabling it by default later on) makes sense to me, though, still.
Overall, this looks good to me, but I had one suggestion about the option.
const options_ = merge({ | ||
playerOptions: { | ||
enableSmoothSeeking: false | ||
} | ||
}, options); | ||
|
||
super(player, options_); |
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.
while it makes sense for this to be a player option, I think that rather than setting a default player option here, we should have it be translated into a seek-bar option called enableSmoothSeeking
.
Maybe something like this (I didn't verify this works)
const options_ = merge({ | |
playerOptions: { | |
enableSmoothSeeking: false | |
} | |
}, options); | |
super(player, options_); | |
const opts = merge({ | |
enableSmoothSeeking: options.playerOptions.enableSmoothSeeking ?? false | |
}, options); | |
super(player, opts); |
Then below, it could use this.options_.enableSmoothSeeking
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.
I guess the alternative would be to always do this.player().options().enableSmoothSeeking
(then someone could more easily update this on the fly and won't need to drill down to the seek bar via player.controlBar.progressControl.seekBar.options_.playerOptions.enableSmoothSeeking = true
, which I had to do to test this out. However, I think making it a seek-bar option is fine and makes sense.
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.
@gkatsev thanks for the suggestion.
I guess the alternative would be to always do
this.player().options().enableSmoothSeeking
(then someone could more easily update this on the fly and won't need to drill down to the seek bar
Your suggestion is much better because it offers a nicer developer experience.
Here's what the changes could look like:
seek-bar.js
constructor(player, options) {
super(player, options);
this.setEventHandlers_();
}
handleMouseMove(event, mouseDown = false) {
// ...
if (this.player_.options_.enableSmoothSeeking) {
this.update();
}
}
time-display.js
constructor(player, options) {
super(player, options);
this.on(player, ['timeupdate', 'ended', 'seeking'], (e) => this.update(e));
this.updateTextNode_();
}
update(event) {
if (!this.player_.options_.enableSmoothSeeking && event.type === 'seeking') {
return;
}
this.updateContent(event);
}
These changes remove merge
options
, reducing the number of lines of code to maintain. As a result, a developer will be able to toggle the smooth seeking on the fly:
player.options({enableSmoothSeeking : true});
player.options({enableSmoothSeeking : false});
Finally, relying directly on player options is something already done for other components: clickable-component
, live-tracker
, poster-image
and picture-in-picture-toggle
.
What do you think about these changes?
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.
Sounds good to me!
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.
@misteroneill thank you for the feedback, I'll try to make the changes by the end of the week.
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.
I pushed the changes. However, I don't see where I can add the documentation for this new option.
Also, appreciate all the PRs you've been opening, thanks! |
@gkatsev thank you all for taking the time to review these PRs, and if it benefits the community, all the better. |
Echoing what @gkatsev said, it's a huge help and great to see such active contribution from a community member! Thanks! |
11de73b
to
396e196
Compare
…is set Updating cache_.currentTime as soon as the currentTime is set avoids having to wait for the timeupdate event, which results in: - making cache_.currentTime more reliable - updating the progress bar on mouse up after dragging when the media is paused. See also: videojs#6232, videojs#6234, videojs#6370, videojs#6372
Adds a player option called enableSmoothSeeking, which is false by default, to provide a smoother seeking experience on mobile and desktop devices. Usage: ```javascript // Enables the smooth seeking const player = videojs('player', {enableSmoothSeeking: true}); // Disable the smooth seeking player.options({enableSmoothSeeking: false}); ``` - **player.js** add an `option` called `enableSmoothSeeking` - **time-display.js** add a listener to the `seeking` event if `enableSmoothSeeking` is `true` allowing to update the `CurrentTimeDisplay` and `RemainingTimeDisplay` in real time - **seek-bar.js** `update` the seek bar on `mousemove` event if `enableSmoothSeeking` is `true` - add test cases
396e196
to
5b8b883
Compare
Should this still have the needs-updates tag? |
@mister-ben I've implemented @gkatsev's suggestions (thanks again), which improves the developer experience. From my point of view, it looks like everything has been addressed. |
Great, let's get this merged before the next minor release then. We'll need to add it to the options guide in the videos.com repo too. |
Documents the `enableSmoothSeeking` option introduced in videojs 8.9.0. Refers videojs/video.js#8287
Documents the `enableSmoothSeeking` option introduced in videojs 8.9.0. Refers videojs/video.js#8287
Description
This PR adds a player option called
enableSmoothSeeking
, which isfalse
by default, to provide a smoother seeking experience on mobile and desktop devices.player-smooth-seek.webm
This PR includes the fix #8285 and should fix #8283.
How to use it?
Specific Changes proposed
option
calledenableSmoothSeeking
seeking
event ifenableSmoothSeeking
istrue
allowing to update theCurrentTimeDisplay
andRemainingTimeDisplay
in real timeupdate
the seek bar onmousemove
event ifenableSmoothSeeking
istrue
player.currentTime
modificationBenchmark
The number of calls to the
update
method when the player isplaying
versus whenseeking
with smooth seeking enabled. The test was performed 10 times in a row and consisted of a counter that incremented by one on each call. It was inserted in the anonymous function provided torequestNamedAnimationFrame
of theupdate
method.The duration of each round was 5 seconds. The
enableInterval_
it started when theplay
button was clicked and stopped at the end of thesetTimeout
. ThehandleMouseMove
it started on themousedown
, then was followed by frantic movement on the seek bar and stopped at the end of thesetTimeout
.Requirements Checklist