Skip to content

Commit

Permalink
fix: improve enabling liveui when switching sources (#7510)
Browse files Browse the repository at this point in the history
We try and enable the liveui on canplay, however, we only do it the first time after the LiveTracker is enabled. This means that if you change sources, we may not catch that the liveui should be enabled. This is particularly important for browsers where native playback is used, like Safari, as the metadata may not be available until canplay.

This is a follow-up from #7114 which enabled listening to canplay but didn't account for switching videos in the same player.
  • Loading branch information
gkatsev authored Nov 11, 2021
1 parent 8497a2b commit 6c67c30
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/live-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class LiveTracker extends Component {
this.on(this.player_, 'durationchange', (e) => this.handleDurationchange(e));
// we should try to toggle tracking on canplay as native playback engines, like Safari
// may not have the proper values for things like seekableEnd until then
this.one(this.player_, 'canplay', () => this.toggleTracking());
this.on(this.player_, 'canplay', () => this.toggleTracking());

// we don't need to track live playback if the document is hidden,
// also, tracking when the document is hidden can
Expand Down
22 changes: 22 additions & 0 deletions test/unit/live-tracker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ QUnit.module('LiveTracker', () => {
assert.equal(liveEdgeChange, 3, 'liveedgechange fired again');
});

QUnit.test('with canplay', function(assert) {
let duration = Infinity;

this.player.seekable = () => createTimeRanges(0, 30);
this.player.duration = () => duration;

assert.notOk(this.liveTracker.isTracking(), 'not started');

this.player.trigger('canplay');
assert.ok(this.liveTracker.isTracking(), 'started');

// end the video by triggering a duration change so we toggle off the liveui
duration = 5;
this.player.trigger('durationchange');
assert.notOk(this.liveTracker.isTracking(), 'not started');

// pretend we loaded a new source and we got a canplay
duration = Infinity;
this.player.trigger('canplay');
assert.ok(this.liveTracker.isTracking(), 'started');
});

QUnit.module('tracking', {
beforeEach() {
this.clock = sinon.useFakeTimers();
Expand Down

0 comments on commit 6c67c30

Please sign in to comment.