Skip to content

Commit

Permalink
fix: Add ManagedMediaSource support in MediaSource polyfill (#6361)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Apr 8, 2024
1 parent e74d90a commit 938776c
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions lib/polyfill/mediasource.js
Expand Up @@ -30,7 +30,7 @@ shaka.polyfill.MediaSource = class {
// platform detection tricks to decide which patches to install.
const safariVersion = shaka.util.Platform.safariVersion();

if (!window.MediaSource) {
if (!window.MediaSource && !window.ManagedMediaSource) {
shaka.log.info('No MSE implementation available.');
} else if (shaka.util.Platform.isChromecast()) {
shaka.log.info('Patching Chromecast MSE bugs.');
Expand Down Expand Up @@ -158,12 +158,25 @@ shaka.polyfill.MediaSource = class {
* @private
*/
static rejectContainer_(container) {
const isTypeSupported = MediaSource.isTypeSupported;
const isTypeSupported =
// eslint-disable-next-line no-restricted-syntax
MediaSource.isTypeSupported.bind(MediaSource);

MediaSource.isTypeSupported = (mimeType) => {
const actualContainer = shaka.util.MimeUtils.getContainerType(mimeType);
return actualContainer != container && isTypeSupported(mimeType);
};

if (window.ManagedMediaSource) {
const isTypeSupportedManaged =
// eslint-disable-next-line no-restricted-syntax
ManagedMediaSource.isTypeSupported.bind(ManagedMediaSource);

window.ManagedMediaSource.isTypeSupported = (mimeType) => {
const actualContainer = shaka.util.MimeUtils.getContainerType(mimeType);
return actualContainer != container && isTypeSupportedManaged(mimeType);
};
}
}

/**
Expand All @@ -175,12 +188,25 @@ shaka.polyfill.MediaSource = class {
* @private
*/
static rejectCodec_(codec) {
const isTypeSupported = MediaSource.isTypeSupported;
const isTypeSupported =
// eslint-disable-next-line no-restricted-syntax
MediaSource.isTypeSupported.bind(MediaSource);

MediaSource.isTypeSupported = (mimeType) => {
const actualCodec = shaka.util.MimeUtils.getCodecBase(mimeType);
return actualCodec != codec && isTypeSupported(mimeType);
};

if (window.ManagedMediaSource) {
const isTypeSupportedManaged =
// eslint-disable-next-line no-restricted-syntax
ManagedMediaSource.isTypeSupported.bind(ManagedMediaSource);

window.ManagedMediaSource.isTypeSupported = (mimeType) => {
const actualCodec = shaka.util.MimeUtils.getCodecBase(mimeType);
return actualCodec != codec && isTypeSupportedManaged(mimeType);
};
}
}

/**
Expand Down

0 comments on commit 938776c

Please sign in to comment.