Skip to content

Commit

Permalink
Fix missing details if subtitle changed synchronously after loaded an…
Browse files Browse the repository at this point in the history
…d before onLoaded callback (#6424)
  • Loading branch information
iamboorrito committed May 22, 2024
1 parent 238f217 commit a16912b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
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

0 comments on commit a16912b

Please sign in to comment.