Skip to content

Commit

Permalink
feat: only polyfill MCap for non Android-based Cast devices. (#4170)
Browse files Browse the repository at this point in the history
Related to #4164 (comment)
  • Loading branch information
Álvaro Velad Galván committed Apr 28, 2022
1 parent feefd7b commit 11321d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/polyfill/media_capabilities.js
Expand Up @@ -24,8 +24,8 @@ shaka.polyfill.MediaCapabilities = class {
* @export
*/
static install() {
// Since MediaCapabilities is not fully supported on Chromecast yet, we
// should always install polyfill for Chromecast.
// Since MediaCapabilities is not fully supported on some Chromecast yet,
// we should always install polyfill for all Chromecast not Android-based.
// TODO: re-evaluate MediaCapabilities in the future versions of Chromecast.
// Since MediaCapabilities implementation is buggy in Apple browsers, we
// should always install polyfill for Apple browsers.
Expand All @@ -37,10 +37,16 @@ shaka.polyfill.MediaCapabilities = class {
// See: https://github.com/shaka-project/shaka-player/issues/3582
// TODO: re-evaluate MediaCapabilities in the future versions of PS5
// Browsers.
if (!shaka.util.Platform.isChromecast() &&
!shaka.util.Platform.isApple() &&
!shaka.util.Platform.isPS5() &&
navigator.mediaCapabilities) {
let canUseNativeMCap = true;
if (shaka.util.Platform.isApple() ||
shaka.util.Platform.isPS5() ||
shaka.util.Platform.isChromecast()) {
canUseNativeMCap = false;
}
if (shaka.util.Platform.isAndroidCastDevice()) {
canUseNativeMCap = true;
}
if (canUseNativeMCap && navigator.mediaCapabilities) {
shaka.log.info(
'MediaCapabilities: Native mediaCapabilities support found.');
return;
Expand Down
10 changes: 10 additions & 0 deletions lib/util/platform.js
Expand Up @@ -163,6 +163,16 @@ shaka.util.Platform = class {
return shaka.util.Platform.userAgentContains_('CrKey');
}

/**
* Check if the current platform is a Android-based Cast devices.
*
* @return {boolean}
*/
static isAndroidCastDevice() {
return shaka.util.Platform.isChromecast() &&
shaka.util.Platform.userAgentContains_('Android');
}

/**
* Check if the current platform is Google Chrome.
*
Expand Down

0 comments on commit 11321d8

Please sign in to comment.