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

Bugfix for subtitle loading after hls.stopload() was used #3063

Merged
Merged
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/controller/subtitle-stream-controller.js
Expand Up @@ -40,6 +40,18 @@ export class SubtitleStreamController extends BaseStreamController {
this._onMediaSeeking = this.onMediaSeeking.bind(this);
}

startLoad () {
this.stopLoad();
this.state = State.IDLE;

// Check if we already have a track with necessary details to load fragments
const currentTrack = this.tracks[this.currentTrackId];
if (currentTrack && currentTrack.details) {
this.setInterval(TICK_INTERVAL);
this.tick();
}
}

onSubtitleFragProcessed (data) {
const { frag, success } = data;
this.fragPrevious = frag;
Expand Down Expand Up @@ -103,6 +115,11 @@ export class SubtitleStreamController extends BaseStreamController {
if (!frag || frag.type !== 'subtitle') {
return;
}

if (this.fragCurrent && this.fragCurrent.loader) {
this.fragCurrent.loader.abort();
}

this.state = State.IDLE;
}

Expand Down Expand Up @@ -237,6 +254,7 @@ export class SubtitleStreamController extends BaseStreamController {

stopLoad () {
this.lastAVStart = 0;
this.fragPrevious = null;
super.stopLoad();
}

Expand All @@ -245,6 +263,31 @@ export class SubtitleStreamController extends BaseStreamController {
}

onMediaSeeking () {
this.fragPrevious = null;
// if (this.state === State.FRAG_LOADING) {
// WIP not reliable as the loader is active in State.IDLE

netTrekfd marked this conversation as resolved.
Show resolved Hide resolved
if (this.fragCurrent) {
const currentTime = this.media ? this.media.currentTime : null;
const tolerance = this.config.maxFragLookUpTolerance;
const fragStartOffset = this.fragCurrent.start - tolerance;
const fragEndOffset = this.fragCurrent.start + this.fragCurrent.duration + tolerance;

// check if we seek position will be out of currently loaded frag range : if out cancel frag load, if in, don't do anything
netTrekfd marked this conversation as resolved.
Show resolved Hide resolved
if (currentTime < fragStartOffset || currentTime > fragEndOffset) {
if (this.fragCurrent.loader) {
this.fragCurrent.loader.abort();
}

this.fragmentTracker.removeFragment(this.fragCurrent);
this.fragCurrent = null;
this.fragPrevious = null;

// switch to IDLE state to load new fragment
this.state = State.IDLE;

// speed up things
this.tick();
}
}
}
}