mirror of
https://github.com/videojs/video.js.git
synced 2025-01-02 06:32:07 +02:00
fix(liveui): do not seek to live on first seek when autoplaying a live stream (#6062)
Before listening for the play/timeupdate combination when starting the LiveTracker, check if the player has already started playback.
This commit is contained in:
parent
9d941c0087
commit
70ba84eb6a
@ -110,16 +110,23 @@ class LiveTracker extends Component {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we haven't seen a timeupdate, we need to check whether playback
|
||||
// began before this component started tracking. This can happen commonly
|
||||
// when using autoplay.
|
||||
if (!this.timeupdateSeen_) {
|
||||
this.timeupdateSeen_ = this.player_.hasStarted();
|
||||
}
|
||||
|
||||
this.trackingInterval_ = this.setInterval(this.trackLive_, 30);
|
||||
this.trackLive_();
|
||||
|
||||
this.on(this.player_, 'play', this.trackLive_);
|
||||
this.on(this.player_, 'pause', this.trackLive_);
|
||||
this.one(this.player_, 'play', this.handlePlay);
|
||||
|
||||
// this is to prevent showing that we are not live
|
||||
// before a video starts to play
|
||||
if (!this.timeupdateSeen_) {
|
||||
this.one(this.player_, 'play', this.handlePlay);
|
||||
this.handleTimeupdate = () => {
|
||||
this.timeupdateSeen_ = true;
|
||||
this.handleTimeupdate = null;
|
||||
|
@ -153,6 +153,44 @@ QUnit.module('LiveTracker', () => {
|
||||
assert.equal(playCalls, 0, 'should not have called play');
|
||||
});
|
||||
|
||||
QUnit.test('seeks to live edge on the first timeupdate after playback is requested', function(assert) {
|
||||
sinon.spy(this.liveTracker, 'seekToLiveEdge');
|
||||
|
||||
// Begin live tracking.
|
||||
this.player.duration(Infinity);
|
||||
assert.ok(this.liveTracker.seekToLiveEdge.notCalled, 'seekToLiveEdge was not called yet');
|
||||
|
||||
this.player.trigger('play');
|
||||
this.player.trigger('playing');
|
||||
assert.ok(this.liveTracker.seekToLiveEdge.notCalled, 'seekToLiveEdge was not called yet');
|
||||
|
||||
this.player.trigger('timeupdate');
|
||||
assert.ok(this.liveTracker.seekToLiveEdge.calledOnce, 'seekToLiveEdge was called');
|
||||
|
||||
this.player.trigger('timeupdate');
|
||||
assert.ok(this.liveTracker.seekToLiveEdge.calledOnce, 'seekToLiveEdge was not called on subsequent timeupdate');
|
||||
});
|
||||
|
||||
QUnit.test('does not seek to live edge on the first timeupdate after playback is requested if playback already began', function(assert) {
|
||||
sinon.spy(this.liveTracker, 'seekToLiveEdge');
|
||||
|
||||
// Begin live tracking.
|
||||
this.liveTracker.stopTracking();
|
||||
this.player.hasStarted = () => true;
|
||||
this.liveTracker.startTracking();
|
||||
assert.ok(this.liveTracker.seekToLiveEdge.notCalled, 'seekToLiveEdge was not called');
|
||||
|
||||
this.player.trigger('play');
|
||||
this.player.trigger('playing');
|
||||
assert.ok(this.liveTracker.seekToLiveEdge.notCalled, 'seekToLiveEdge was not called');
|
||||
|
||||
this.player.trigger('timeupdate');
|
||||
assert.ok(this.liveTracker.seekToLiveEdge.notCalled, 'seekToLiveEdge was not called');
|
||||
|
||||
this.player.trigger('timeupdate');
|
||||
assert.ok(this.liveTracker.seekToLiveEdge.notCalled, 'seekToLiveEdge was not called');
|
||||
});
|
||||
|
||||
QUnit.test('single seekable, helpers should be correct', function(assert) {
|
||||
// simple
|
||||
this.player.seekable = () => createTimeRanges(10, 50);
|
||||
|
Loading…
Reference in New Issue
Block a user