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

load audio playlist on MANIFEST_PARSED #2340

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
35 changes: 21 additions & 14 deletions src/controller/audio-track-controller.js
Expand Up @@ -91,6 +91,8 @@ class AudioTrackController extends TaskLoop {
onManifestParsed (data) {
const tracks = this.tracks = data.audioTracks || [];
this.hls.trigger(Event.AUDIO_TRACKS_UPDATED, { audioTracks: tracks });

this._selectAudioGroup(this.hls.nextLoadLevel);
robwalch marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -150,20 +152,7 @@ class AudioTrackController extends TaskLoop {
* @param {*} data
*/
onLevelLoaded (data) {
// FIXME: crashes because currentLevel is undefined
// const levelInfo = this.hls.levels[this.hls.currentLevel];

const levelInfo = this.hls.levels[data.level];

if (!levelInfo.audioGroupIds) {
return;
}

const audioGroupId = levelInfo.audioGroupIds[levelInfo.urlId];
if (this.audioGroupId !== audioGroupId) {
this.audioGroupId = audioGroupId;
this._selectInitialAudioTrack();
}
this._selectAudioGroup(data.level);
}

/**
Expand Down Expand Up @@ -252,6 +241,24 @@ class AudioTrackController extends TaskLoop {
this._updateTrack(this._trackId);
}

/**
* @param levelId
* @private
*/
_selectAudioGroup (levelId) {
const levelInfo = this.hls.levels[levelId];

if (!levelInfo || !levelInfo.audioGroupIds) {
return;
}

const audioGroupId = levelInfo.audioGroupIds[levelInfo.urlId];
if (this.audioGroupId !== audioGroupId) {
this.audioGroupId = audioGroupId;
this._selectInitialAudioTrack();
}
}

/**
* Select initial track
* @private
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/controller/audio-track-controller.js
Expand Up @@ -80,6 +80,42 @@ describe('AudioTrackController', function () {
});
});

it('should select audioGroupId and trigger AUDIO_TRACK_SWITCHING', function (done) {
hls.on(Hls.Events.AUDIO_TRACK_SWITCHING, (event, data) => {
done();
});

const levels = [
{
urlId: 1,
audioGroupIds: ['1', '2']
}
];

hls.levelController = {
levels
};

const newLevelInfo = levels[0];
const newGroupId = newLevelInfo.audioGroupIds[newLevelInfo.urlId];

audioTrackController.audioGroupId = '1';
audioTrackController.tracks = tracks;
audioTrackController.audioTrack = 2;

// current track name
const audioTrackName = tracks[audioTrackController.audioTrack].name;

audioTrackController.onManifestParsed({
audioTracks: tracks
});

// group has switched
expect(audioTrackController.audioGroupId).to.equal(newGroupId);
// name is still the same
expect(tracks[audioTrackController.audioTrack].name).to.equal(audioTrackName);
});

describe('_needsTrackLoading', function () {
it('should not need loading because the audioTrack is embedded in the main playlist', function () {
expect(audioTrackController._needsTrackLoading({ details: { live: true } })).to.be.false;
Expand Down