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 missing details if subtitle changed synchronously after loaded and before onLoaded callback #6424

Merged
merged 1 commit into from
May 22, 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
8 changes: 6 additions & 2 deletions src/controller/subtitle-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ export class SubtitleStreamController
this.warn(`Subtitle tracks were reset while loading level ${trackId}`);
return;
}
const track: Level = levels[currentTrackId];
if (trackId >= levels.length || trackId !== currentTrackId || !track) {
const track: Level = levels[trackId];
if (trackId >= levels.length || !track) {
return;
}
this.log(
Expand Down Expand Up @@ -320,6 +320,10 @@ export class SubtitleStreamController
track.details = newDetails;
this.levelLastLoaded = track;

if (trackId !== currentTrackId) {
return;
}

if (!this.startFragRequested && (this.mainDetails || !newDetails.live)) {
this.setStartPosition(this.mainDetails || newDetails, sliding);
}
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/controller/subtitle-track-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,33 @@ describe('SubtitleTrackController', function () {
expect(playlistLoadedSpy).to.have.been.calledOnce;
});

it('retains loaded details on track if active track synchronously set to something else', function () {
const playlistLoadedSpy = sandbox.spy(
subtitleTrackController,
'playlistLoaded',
);
subtitleTrackController.startLoad();
(subtitleTrackController as any).trackId = 1;
(subtitleTrackController as any).currentTrack = subtitleTracks[1];

const mockLoadedEvent = {
id: 1,
groupId: 'default-text-group',
details: { foo: 'bar' } as any,
stats: new LoadStats(),
networkDetails: {},
deliveryDirectives: null,
};

hls.subtitleTrack = -1;
hls.trigger(Events.SUBTITLE_TRACK_LOADED, mockLoadedEvent);

expect(subtitleTracks[1].details).not.to.be.undefined;
expect((subtitleTrackController as any).timer).to.equal(-1);
// We will still emit playlist loaded since we did load and store the details
expect(playlistLoadedSpy).to.have.been.called;
});

it('does not set the reload timer if loading has not started', function () {
const details = new LevelDetails('');
subtitleTrackController.stopLoad();
Expand Down
Loading