Skip to content

Commit

Permalink
test: Fix Fuchsia background-video errors (#6579)
Browse files Browse the repository at this point in the history
In some cases, Fuchsia Chromecast tests will fail with the error: "The
play() request was interrupted because video-only background media was
paused to save power."

This resolves the issue by ensuring tests run un-muted on that platform,
based on this Chrome code, which indicates the "paused to save power"
logic does not activate when sound is playing:
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/platform/media/web_media_player_impl.cc;l=3535;drc=d23075f3

This also fixes two places in our tests where the `createVideoElement()`
was bypassed. This should always be used, because it is a central place
to apply workarounds such as this.
  • Loading branch information
joeyparrish committed May 11, 2024
1 parent 03ee77e commit ddabe93
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
20 changes: 20 additions & 0 deletions lib/util/platform.js
Expand Up @@ -197,6 +197,17 @@ shaka.util.Platform = class {
return Platform.isChromecast() && Platform.isAndroid();
}

/**
* Check if the current platform is a Google Chromecast with Android
* (i.e. Chromecast with GoogleTV).
*
* @return {boolean}
*/
static isFuchsiaCastDevice() {
const Platform = shaka.util.Platform;
return Platform.isChromecast() && Platform.isFuchsia();
}

/**
* Returns a major version number for Chrome, or Chromium-based browsers.
*
Expand Down Expand Up @@ -459,6 +470,15 @@ shaka.util.Platform = class {
return shaka.util.Platform.userAgentContains_('Android');
}

/**
* Return true if the platform is a Fuchsia, regardless of the browser.
*
* @return {boolean}
*/
static isFuchsia() {
return shaka.util.Platform.userAgentContains_('Fuchsia');
}

/**
* Return true if the platform is controlled by a remote control.
*
Expand Down
3 changes: 1 addition & 2 deletions test/offline/storage_integration.js
Expand Up @@ -736,8 +736,7 @@ filterDescribe('Storage', storageSupport, () => {
/** @type {!shaka.util.EventManager} */
let eventManager;
/** @type {!HTMLVideoElement} */
const videoElement = /** @type {!HTMLVideoElement} */(
document.createElement('video'));
const videoElement = shaka.test.UiUtils.createVideoElement();

beforeEach(async () => {
netEngine = makeNetworkEngine();
Expand Down
8 changes: 5 additions & 3 deletions test/test/util/ui_utils.js
Expand Up @@ -171,9 +171,11 @@ shaka.test.UiUtils = class {
const video = /** @type {!HTMLVideoElement} */(document.createElement(
'video'));

// Tizen has issues with audio-only playbacks on muted video elements.
// Don't mute Tizen.
if (!shaka.util.Platform.isTizen()) {
// Some platforms have issues with audio-only playbacks on muted video
// elements. Don't mute them.
// Fuchsia reference: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/platform/media/web_media_player_impl.cc;l=3535;drc=d23075f3
if (!shaka.util.Platform.isTizen() &&
!shaka.util.Platform.isFuchsiaCastDevice()) {
video.muted = true;
}
video.width = 600;
Expand Down
3 changes: 1 addition & 2 deletions test/ui/ui_unit.js
Expand Up @@ -123,8 +123,7 @@ describe('UI', () => {
// multi-video use case. It could be replaces with any other
// (reasonable) number.
for (let i = 0; i < 4; i++) {
const video = /** @type {!HTMLVideoElement} */
(document.createElement('video'));
const video = shaka.test.UiUtils.createVideoElement();

document.body.appendChild(video);
videos.push(video);
Expand Down

0 comments on commit ddabe93

Please sign in to comment.