Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(UI): Add config to preferDocumentPictureInPicture #5690

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions ui/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,8 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
* @export
*/
isPiPAllowed() {
if ('documentPictureInPicture' in window) {
if ('documentPictureInPicture' in window &&
this.config_.preferDocumentPictureInPicture) {
return true;
}
if (document.pictureInPictureEnabled) {
Expand All @@ -663,7 +664,8 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
* @export
*/
isPiPEnabled() {
if ('documentPictureInPicture' in window) {
if ('documentPictureInPicture' in window &&
this.config_.preferDocumentPictureInPicture) {
return !!window.documentPictureInPicture.window;
} else {
return !!document.pictureInPictureElement;
Expand All @@ -673,7 +675,8 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
/** @export */
async togglePiP() {
try {
if ('documentPictureInPicture' in window) {
if ('documentPictureInPicture' in window &&
this.config_.preferDocumentPictureInPicture) {
await this.toggleDocumentPictureInPicture_();
} else if (!document.pictureInPictureElement) {
// If you were fullscreen, leave fullscreen first.
Expand Down
9 changes: 8 additions & 1 deletion ui/externs/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ shaka.extern.UIVolumeBarColors;
* enableTooltips: boolean,
* keyboardSeekDistance: number,
* keyboardLargeSeekDistance: number,
* fullScreenElement: HTMLElement
* fullScreenElement: HTMLElement,
* preferDocumentPictureInPicture: boolean
* }}
*
* @property {!Array.<string>} controlPanelElements
Expand Down Expand Up @@ -193,6 +194,12 @@ shaka.extern.UIVolumeBarColors;
* @property {HTMLElement} fullScreenElement
* DOM element on which fullscreen will be done.
* Defaults to Shaka Player Container.
* @property {boolean} preferDocumentPictureInPicture
* Indicates whether the Document Picture in Picture API is preferred or the
* Video Element Picture in Picture API is preferred.
* Changing this property in mid-playback may produce undesired behavior if
* you are already in PiP.
* Defaults to true.
* @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 @@ -245,6 +245,7 @@ shaka.ui.Overlay = class {
keyboardSeekDistance: 5,
keyboardLargeSeekDistance: 60,
fullScreenElement: this.videoContainer_,
preferDocumentPictureInPicture: true,
};

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