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

fix: progress bar sometimes is not filled on 100% #8633

Merged
merged 2 commits into from
May 3, 2024
Merged
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
6 changes: 4 additions & 2 deletions src/js/control-bar/progress-control/seek-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class SeekBar extends Slider {
this.update_ = Fn.bind_(this, this.update);
this.update = Fn.throttle(this.update_, Fn.UPDATE_REFRESH_INTERVAL);

this.on(this.player_, ['ended', 'durationchange', 'timeupdate'], this.update);
this.on(this.player_, ['durationchange', 'timeupdate'], this.update);
this.on(this.player_, ['ended'], this.update_);
if (this.player_.liveTracker) {
this.on(this.player_.liveTracker, 'liveedgechange', this.update);
}
Expand Down Expand Up @@ -478,7 +479,8 @@ class SeekBar extends Slider {
dispose() {
this.disableInterval_();

this.off(this.player_, ['ended', 'durationchange', 'timeupdate'], this.update);
this.off(this.player_, ['durationchange', 'timeupdate'], this.update);
this.off(this.player_, ['ended'], this.update_);
if (this.player_.liveTracker) {
this.off(this.player_.liveTracker, 'liveedgechange', this.update);
}
Expand Down
47 changes: 47 additions & 0 deletions test/unit/controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,53 @@ QUnit.test("SeekBar doesn't set scrubbing on mouse down, only on mouse move", fu
player.dispose();
});

QUnit.test('SeekBar should be filled on 100% when the video/audio ends', function(assert) {
const player = TestHelpers.makePlayer();
const seekBar = player.controlBar.progressControl.seekBar;
const oldRAF = window.requestAnimationFrame;
const oldCAF = window.cancelAnimationFrame;

window.requestAnimationFrame = (fn) => window.setTimeout(fn, 1);
window.cancelAnimationFrame = (id) => window.clearTimeout(id);

player.triggerReady();
player.duration(1.5);

this.clock.tick(30);
player.trigger('timeupdate');
this.clock.tick(1);

assert.equal(seekBar.duration_, 1.5, 'SeekBar duration should equal player duration');
assert.equal(seekBar.currentTime_, 0, 'SeekBar current time should be zero on start');
assert.equal(seekBar.getPercent(), 0, 'SeekBar percent should be zero on start');

this.clock.tick(30);
player.currentTime(0.75);
player.trigger('timeupdate');
this.clock.tick(1);

assert.equal(seekBar.currentTime_, 0.75, 'SeekBar currentTime should equal player currentTime');
assert.equal(seekBar.getPercent(), 0.5, 'SeekBar percent equal to 50%');

this.clock.tick(30);
player.currentTime(1.495);
player.trigger('timeupdate');
this.clock.tick(1);
player.currentTime(1.5);
// The following 'timeupdate' should be wiped out by the throttle function!
player.trigger('timeupdate');
// The following 'ended' shouldn't be wiped out by the throttle function!
player.trigger('ended');
this.clock.tick(1);

assert.equal(seekBar.currentTime_, 1.5, 'SeekBar currentTime should equal player currentTime');
assert.equal(seekBar.getPercent(), 1, 'SeekBar percent equal to 100%');
player.dispose();

window.requestAnimationFrame = oldRAF;
window.cancelAnimationFrame = oldCAF;
});

QUnit.test('playback rate button is hidden by default', function(assert) {
assert.expect(1);

Expand Down
Loading