Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

always activate loading in segment loaders after a seek #1234

Merged
merged 2 commits into from
Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 2 additions & 9 deletions src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1413,15 +1413,8 @@ export class MasterPlaylistController extends videojs.EventTarget {
this.subtitleSegmentLoader_.abort();
}

if (!this.tech_.paused()) {
this.mainSegmentLoader_.load();
if (this.audioPlaylistLoader_) {
this.audioSegmentLoader_.load();
}
if (this.subtitlePlaylistLoader_) {
this.subtitleSegmentLoader_.load();
}
}
// start segment loader loading in case they are paused
this.load();
}

/**
Expand Down
48 changes: 47 additions & 1 deletion test/master-playlist-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,52 @@ function(assert) {
assert.equal(MPC.mediaSource.readyState, 'ended', 'Media Source ended');
});

QUnit.test('Segment loaders are unpaused when seeking after player has ended',
function(assert) {
openMediaSource(this.player, this.clock);

const videoMedia = '#EXTM3U\n' +
'#EXT-X-VERSION:3\n' +
'#EXT-X-PLAYLIST-TYPE:VOD\n' +
'#EXT-X-MEDIA-SEQUENCE:0\n' +
'#EXT-X-TARGETDURATION:10\n' +
'#EXTINF:10,\n' +
'video-0.ts\n' +
'#EXT-X-ENDLIST\n';

let ended = 0;

this.masterPlaylistController.mainSegmentLoader_.on('ended', () => ended++);

this.player.tech_.trigger('play');

// master
this.standardXHRResponse(this.requests.shift());

// media
this.standardXHRResponse(this.requests.shift(), videoMedia);

// segment
this.standardXHRResponse(this.requests.shift());

assert.notOk(this.masterPlaylistController.mainSegmentLoader_.paused(),
'segment loader not yet paused');

this.masterPlaylistController.mediaSource.sourceBuffers[0].trigger('updateend');

assert.ok(this.masterPlaylistController.mainSegmentLoader_.paused(),
'segment loader is paused after ending');
assert.equal(ended, 1, 'segment loader triggered ended event');

this.player.currentTime(5);

this.clock.tick(1);

assert.notOk(this.masterPlaylistController.mainSegmentLoader_.paused(),
'segment loader unpaused after a seek');
assert.equal(ended, 1, 'segment loader did not trigger ended event again yet');
})

QUnit.test('detects if the player is stuck at the playlist end', function(assert) {
let playlistCopy = Hls.Playlist.playlistEnd;

Expand Down Expand Up @@ -2096,7 +2142,7 @@ QUnit.test('subtitle segment loader resets on seeks', function(assert) {

assert.equal(resetCount, 1, 'reset subtitle segment loader');
assert.equal(abortCount, 1, 'aborted subtitle segment loader');
assert.equal(loadCount, 0, 'did not call load on subtitle segment loader');
assert.equal(loadCount, 1, 'called load on subtitle segment loader');

this.player.play();
resetCount = 0;
Expand Down
2 changes: 1 addition & 1 deletion test/videojs-contrib-hls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2780,7 +2780,7 @@ QUnit.test('cleans up the buffer when loading VOD segments', function(assert) {
this.clock.tick(1);
this.player.currentTime(120);
this.player.tech_.hls.mediaSource.sourceBuffers[0].trigger('updateend');
this.clock.tick(1);
this.clock.tick(2);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was needed because previously, after an updateend event, SegmentLoader.handleUpdateEnd_ would call SegmentLoader.monitorBuffer_ which would setup a timeout to call SegmentLoader.fillBuffer_ on the next clock tick, but with the addition of calling load on a seek, this would clear that timeout and set a new one for the next clock tick.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be good to add as a comment above the clock tick (since clock ticks are generally pretty mysterious through our tests).

this.standardXHRResponse(this.requests[3]);

assert.strictEqual(this.requests[0].url, 'manifest/master.m3u8',
Expand Down