Skip to content

Commit

Permalink
feat(UI): Allow configure the fullscreen mode in VisionOS (#7540)
Browse files Browse the repository at this point in the history
With this config we will use the fullscreen API of the video element
itself if it is available in Vision OS. This is useful to be able to
access 3D experiences that are only allowed with the fullscreen of the
video element itself.
  • Loading branch information
avelad authored Nov 6, 2024
1 parent 84ae806 commit 3bd0978
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
15 changes: 15 additions & 0 deletions lib/util/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,21 @@ shaka.util.Platform = class {
return navigator.platform.toLowerCase().includes('mac');
}

/**
* Return true if the platform is a VisionOS.
*
* @return {boolean}
*/
static isVisionOS() {
if (!shaka.util.Platform.isMac()) {
return false;
}
if (!('xr' in navigator)) {
return false;
}
return true;
}

/**
* Return true if the platform is a Windows, regardless of the browser.
*
Expand Down
29 changes: 25 additions & 4 deletions ui/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ goog.require('shaka.util.EventManager');
goog.require('shaka.util.FakeEvent');
goog.require('shaka.util.FakeEventTarget');
goog.require('shaka.util.IDestroyable');
goog.require('shaka.util.Platform');
goog.require('shaka.util.Timer');

goog.requireType('shaka.Player');
Expand Down Expand Up @@ -603,12 +604,32 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
this.hideSettingsMenusTimer_.tickNow();
}

/**
* @return {boolean}
* @private
*/
shouldUseDocumentFullscreen_() {
if (!document.fullscreenEnabled) {
return false;
}
// When the preferVideoFullScreenInVisionOS configuration value applies,
// we avoid using document fullscreen, even if it is available.
const video = /** @type {HTMLVideoElement} */(this.localVideo_);
if (video.webkitSupportsFullscreen) {
if (this.config_.preferVideoFullScreenInVisionOS &&
shaka.util.Platform.isVisionOS()) {
return false;
}
}
return true;
}

/**
* @return {boolean}
* @export
*/
isFullScreenSupported() {
if (document.fullscreenEnabled) {
if (this.shouldUseDocumentFullscreen_()) {
return true;
}
if (!this.ad_ || !this.ad_.isUsingAnotherMediaElement()) {
Expand All @@ -625,7 +646,7 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
* @export
*/
isFullScreenEnabled() {
if (document.fullscreenEnabled) {
if (this.shouldUseDocumentFullscreen_()) {
return !!document.fullscreenElement;
}
const video = /** @type {HTMLVideoElement} */(this.localVideo_);
Expand All @@ -638,7 +659,7 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
/** @private */
async enterFullScreen_() {
try {
if (document.fullscreenEnabled) {
if (this.shouldUseDocumentFullscreen_()) {
if (document.pictureInPictureElement) {
await document.exitPictureInPicture();
}
Expand Down Expand Up @@ -669,7 +690,7 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {

/** @private */
async exitFullScreen_() {
if (document.fullscreenEnabled) {
if (this.shouldUseDocumentFullscreen_()) {
if (screen.orientation) {
screen.orientation.unlock();
}
Expand Down
9 changes: 8 additions & 1 deletion ui/externs/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ shaka.extern.UIVolumeBarColors;
* refreshTickInSeconds: number,
* displayInVrMode: boolean,
* defaultVrProjectionMode: string,
* setupMediaSession: boolean
* setupMediaSession: boolean,
* preferVideoFullScreenInVisionOS: boolean
* }}
*
* @property {!Array.<string>} controlPanelElements
Expand Down Expand Up @@ -254,6 +255,12 @@ shaka.extern.UIVolumeBarColors;
* the ID3 APIC and TIT2 as image and title in Media Session, and ID3 APIC
* will also be used to change video poster.
* Defaults to true.
* @property {boolean} preferVideoFullScreenInVisionOS
* If true, we will use the fullscreen API of the video element itself if it
* is available in Vision OS. This is useful to be able to access 3D
* experiences that are only allowed with the fullscreen of the video element
* itself.
* Defaults to false.
* @exportDoc
*/
shaka.extern.UIConfiguration;
Expand Down
1 change: 1 addition & 0 deletions ui/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ shaka.ui.Overlay = class {
displayInVrMode: false,
defaultVrProjectionMode: 'equirectangular',
setupMediaSession: true,
preferVideoFullScreenInVisionOS: false,
};

// eslint-disable-next-line no-restricted-syntax
Expand Down

0 comments on commit 3bd0978

Please sign in to comment.