Skip to content

Commit

Permalink
fix: Fix playback with Apple Media Keys polyfill detection (#7958)
Browse files Browse the repository at this point in the history
Backported to v4.9.x
  • Loading branch information
avelad authored and joeyparrish committed Feb 22, 2025
1 parent 947e305 commit 51633c9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4312,7 +4312,7 @@ shaka.hls.HlsParser = class {
shaka.util.Error.Code.HLS_MSE_ENCRYPTED_MP2T_NOT_SUPPORTED);
}

if (shaka.util.Platform.isMediaKeysPolyfilled()) {
if (shaka.util.Platform.isMediaKeysPolyfilled('apple')) {
throw new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.MANIFEST,
Expand Down Expand Up @@ -4452,7 +4452,7 @@ shaka.hls.HlsParser = class {
shaka.util.Error.Code.HLS_MSE_ENCRYPTED_MP2T_NOT_SUPPORTED);
}

if (shaka.util.Platform.isMediaKeysPolyfilled()) {
if (shaka.util.Platform.isMediaKeysPolyfilled('apple')) {
throw new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.MANIFEST,
Expand Down
9 changes: 3 additions & 6 deletions lib/util/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,16 +685,13 @@ shaka.util.Platform = class {
}

/**
* Returns true if MediaKeys is polyfilled
* Returns true if MediaKeys is polyfilled by the specified polyfill.
*
* @param {string=} polyfillType
* @param {string} polyfillType
* @return {boolean}
*/
static isMediaKeysPolyfilled(polyfillType) {
if (polyfillType) {
return polyfillType === window.shakaMediaKeysPolyfill;
}
return !!window.shakaMediaKeysPolyfill;
return polyfillType === window.shakaMediaKeysPolyfill;
}


Expand Down
2 changes: 1 addition & 1 deletion lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ shaka.util.PlayerConfiguration = class {
persistentSessionOnlinePlayback: false,
persistentSessionsMetadata: [],
initDataTransform: (initData, initDataType, drmInfo) => {
if (shaka.util.Platform.isMediaKeysPolyfilled() &&
if (shaka.util.Platform.isMediaKeysPolyfilled('apple') &&
initDataType == 'skd') {
const cert = drmInfo.serverCertificate;
const contentId =
Expand Down
12 changes: 0 additions & 12 deletions test/util/platform_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,6 @@ describe('Platform', () => {
window.shakaMediaKeysPolyfill = shakaMediaKeysPolyfill;
});

it('should return true if media keys are polyfilled', () => {
window.shakaMediaKeysPolyfill = 'webkit';
const result = shaka.util.Platform.isMediaKeysPolyfilled();
expect(result).toBe(true);
});

it('should return false if media keys are not polyfilled', () => {
window.shakaMediaKeysPolyfill = '';
const result = shaka.util.Platform.isMediaKeysPolyfilled();
expect(result).toBe(false);
});

it('should return true with a matching polyfill type', () => {
window.shakaMediaKeysPolyfill = 'webkit';
const result = shaka.util.Platform.isMediaKeysPolyfilled('webkit');
Expand Down

0 comments on commit 51633c9

Please sign in to comment.