Skip to content
Open
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
1 change: 1 addition & 0 deletions api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export type AudioSelectionOption = {
audioCodec?: string;
groupId?: string;
default?: boolean;
flushImmediate?: boolean;
};

// Warning: (ae-missing-release-tag) "AudioStreamController" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down
2 changes: 1 addition & 1 deletion src/controller/audio-track-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class AudioTrackController extends BasePlaylistController {
set audioTrack(newId: number) {
// If audio track is selected from API then don't choose from the manifest default track
this.selectDefaultTrack = false;
this.setAudioTrack(newId);
this.setAudioTrack(newId, this.hls.config.audioPreference?.flushImmediate);
}

get nextAudioTrack(): number {
Expand Down
1 change: 1 addition & 0 deletions src/types/media-playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type AudioSelectionOption = {
audioCodec?: string;
groupId?: string;
default?: boolean;
flushImmediate?: boolean;
};

export type SubtitleSelectionOption = {
Expand Down
40 changes: 39 additions & 1 deletion tests/unit/controller/audio-track-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ describe('AudioTrackController', function () {
});
});

it('should set audio track with flushImmediate=true by default', function () {
it('should set audio track with flushImmediate=true by default (no audioPreference set)', function () {
const triggerSpy = sinon.spy(hls, 'trigger');
audioTrackController.audioTrack = 1;

Expand All @@ -552,5 +552,43 @@ describe('AudioTrackController', function () {
}),
);
});

it('should set audio track with flushImmediate=true when audioPreference.flushImmediate is true', function () {
(hls as unknown as Hls).config.audioPreference = { flushImmediate: true };
const triggerSpy = sinon.spy(hls, 'trigger');
audioTrackController.audioTrack = 1;

expect(audioTrackController.trackId).to.equal(1);
expect(triggerSpy).to.have.been.calledWith(
Events.AUDIO_TRACK_SWITCHING,
sinon.match({
id: 1,
flushImmediate: true,
}),
);
});

it('should set audio track with flushImmediate=false when audioPreference.flushImmediate is false', function () {
(hls as unknown as Hls).config.audioPreference = {
flushImmediate: false,
};
const triggerSpy = sinon.spy(hls, 'trigger');
audioTrackController.audioTrack = 1;

expect(audioTrackController.trackId).to.equal(1);
expect(triggerSpy).to.have.been.calledWith(
Events.AUDIO_TRACK_SWITCHING,
sinon.match({
id: 1,
flushImmediate: false,
}),
);
});

it('should set selectDefaultTrack to false when audioTrack is set from API', function () {
(audioTrackController as any).selectDefaultTrack = true;
audioTrackController.audioTrack = 1;
expect((audioTrackController as any).selectDefaultTrack).to.be.false;
});
});
});
Loading