Skip to content

Commit

Permalink
Merge pull request #2340 from yandex-pcode/load-audio-after-manifest-…
Browse files Browse the repository at this point in the history
…parsed

load audio playlist on MANIFEST_PARSED
  • Loading branch information
robwalch committed Feb 26, 2020
2 parents 7e06413 + 61ed761 commit 88c4ed0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 14 deletions.
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);
}

/**
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

0 comments on commit 88c4ed0

Please sign in to comment.