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: Handle audio only audio track change correctly #1100

Merged
merged 23 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ export class MasterPlaylistController extends videojs.EventTarget {

// if we don't have any demuxed audio tracks
// return an empty array
if (!master && !master.mediaGroups && !master.mediaGroups.AUDIO) {
return [];
if (!master || !master.mediaGroups || !master.mediaGroups.AUDIO) {
return master && master.playlists;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's no master, is it OK that this returns undefined? Would it be better to return []?

The comment above may need to be changed too otherwise. And would returning master.playlists end up returning non audio only tracks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make it return an empty array without a master. It will could end up returning non-audio playlists but if we don't have audio groups and this function is called, which should only happen if we detect that the playlist is audio only, Then we should just return the main playlists.

}

const AUDIO = master.mediaGroups.AUDIO;
Expand Down
59 changes: 59 additions & 0 deletions test/master-playlist-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,64 @@ const sharedHooks = {

QUnit.module('MasterPlaylistController', sharedHooks);

QUnit.test('getAudioTrackPlaylists_', function(assert) {
const mpc = this.masterPlaylistController;
const master = {playlists: [{uri: 'testing'}]};

mpc.master = () => master;

assert.deepEqual(
mpc.getAudioTrackPlaylists_(),
master.playlists,
'no media groups, return main playlists'
);

master.mediaGroups = {
AUDIO: {
main: {
en: {default: true, label: 'en', playlists: [{uri: 'foo'}, {uri: 'bar'}]},
fr: {label: 'fr', playlists: [{uri: 'foo-fr'}, {uri: 'bar-fr'}]}
},
alt: {
en: {default: true, label: 'en', playlists: [{uri: 'fizz'}, {uri: 'bazz'}]},
fr: {label: 'fr', playlists: [{uri: 'fizz-fr'}, {uri: 'bazz-fr'}]}
}
}
};

assert.deepEqual(mpc.getAudioTrackPlaylists_(), [
{uri: 'foo'},
{uri: 'bar'},
{uri: 'fizz'},
{uri: 'bazz'}
], 'returns all dash style en playlist');

mpc.mediaTypes_.AUDIO.groups = {
main: Object.values(master.mediaGroups.AUDIO.main),
alt: Object.values(master.mediaGroups.AUDIO.alt)
};
mpc.mediaTypes_.AUDIO.activeTrack = () => ({label: 'fr'});

assert.deepEqual(mpc.getAudioTrackPlaylists_(), [
{uri: 'foo-fr'},
{uri: 'bar-fr'},
{uri: 'fizz-fr'},
{uri: 'bazz-fr'}
], 'returns all dash style fr playlists');

delete master.mediaGroups.AUDIO.main.fr.playlists;
master.mediaGroups.AUDIO.main.fr.uri = 'fizz-fr';

delete master.mediaGroups.AUDIO.alt.fr.playlists;
master.mediaGroups.AUDIO.alt.fr.uri = 'buzz-fr';

assert.deepEqual(mpc.getAudioTrackPlaylists_(), [
{uri: 'fizz-fr', label: 'fr'},
{uri: 'buzz-fr', label: 'fr'}
], 'returns all fr hls style playlists');

});

QUnit.test('throws error when given an empty URL', function(assert) {
const options = {
src: 'test',
Expand Down Expand Up @@ -5886,3 +5944,4 @@ QUnit.test('should delay loading of new playlist if lastRequest was less than ha

this.env.log.warn.callCount = 0;
});