Skip to content

Commit

Permalink
fix: do not add placeholder for AUDIO groups without a uri
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Jul 15, 2021
1 parent bcc2949 commit 53c11eb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
17 changes: 16 additions & 1 deletion src/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import videojs from 'video.js';
import window from 'global/window';
import { Parser as M3u8Parser } from 'm3u8-parser';
import { resolveUrl } from './resolve-url';
import { getLastParts } from './playlist.js';
import { getLastParts, isAudioOnly } from './playlist.js';

const { log } = videojs;

Expand Down Expand Up @@ -279,11 +279,26 @@ export const addPropertiesToMaster = (master, uri) => {
master.playlists[i].uri = phonyUri;
}
}
const audioOnlyMaster = isAudioOnly(master);

forEachMediaGroup(master, (properties, mediaType, groupKey, labelKey) => {
const groupId = `placeholder-uri-${mediaType}-${groupKey}-${labelKey}`;

// add a playlist array under properties
if (!properties.playlists || !properties.playlists.length) {
// if we have an audio only master and this media group does not have a uri.
// check if it is located in the real list. If it is don't add placeholder
// properties as we should never switch to it.
if (audioOnlyMaster && mediaType === 'AUDIO' && !properties.uri) {
for (let i = 0; i < master.playlists.length; i++) {
const p = master.playlists[i];

if (p.attributes && p.attributes.AUDIO) {
return;
}
}
}

properties.playlists = [Object.assign({}, properties)];
}

Expand Down
22 changes: 19 additions & 3 deletions src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,13 @@ export class MasterPlaylistController extends videojs.EventTarget {
*/
getAudioTrackPlaylists_() {
const master = this.master();
const defaultPlaylists = master && master.playlists || [];

// if we don't have any audio groups then we can only
// assume that the audio tracks are contained in masters
// playlist array, use that or an empty array.
if (!master || !master.mediaGroups || !master.mediaGroups.AUDIO) {
return master && master.playlists || [];
return defaultPlaylists;
}

const AUDIO = master.mediaGroups.AUDIO;
Expand All @@ -427,7 +428,7 @@ export class MasterPlaylistController extends videojs.EventTarget {

// no active track no playlists.
if (!track) {
return [];
return defaultPlaylists;
}

const playlists = [];
Expand All @@ -440,12 +441,27 @@ export class MasterPlaylistController extends videojs.EventTarget {

if (properties.playlists) {
playlists.push.apply(playlists, properties.playlists);
} else {
} else if (properties.uri) {
playlists.push(properties);
} else if (master.playlists.length) {
// if an audio group does not have a uri
// see if we have main playlists that use it as a group.
// if we do then add those to the playlists list.
for (let i = 0; i < master.playlists.length; i++) {
const playlist = master.playlists[i];

if (playlist.attributes && playlist.attributes.AUDIO && playlist.attributes.audio === group) {
playlists.push(playlist);
}
}
}
}
}

if (!playlists.length) {
return defaultPlaylists;
}

return playlists;
}

Expand Down

0 comments on commit 53c11eb

Please sign in to comment.