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

Use "native-picture-in-picture" presentation mode instead of using native element #472

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Changes from 1 commit
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
16 changes: 4 additions & 12 deletions src/internal/adapter/web/WebPresentationModeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class WebPresentationModeManager {
constructor(player: ChromelessPlayer, eventForwarder: DefaultEventDispatcher<PlayerEventMap>) {
this._player = player;
this._eventForwarder = eventForwarder;
this._player.presentation.addEventListener('presentationmodechange', this.updatePresentationMode);
}

get presentationMode(): PresentationMode {
Expand All @@ -39,7 +40,7 @@ export class WebPresentationModeManager {
}
}
} else if (presentationMode === PresentationMode.pip) {
void this._element?.requestPictureInPicture?.();
this._player.presentation.requestMode('native-picture-in-picture');
} else {
if (this._presentationMode === PresentationMode.fullscreen) {
const promise = document[fullscreenAPI.exitFullscreen_]();
Expand All @@ -56,7 +57,7 @@ export class WebPresentationModeManager {
if (presentationMode === PresentationMode.fullscreen) {
this._element?.webkitEnterFullscreen?.();
} else if (presentationMode === PresentationMode.pip) {
this._element?.webkitSetPresentationMode?.(PresentationMode.pip);
this._player.presentation.requestMode('native-picture-in-picture');
} else {
this._element?.webkitSetPresentationMode?.(PresentationMode.inline);
}
Expand All @@ -74,15 +75,6 @@ export class WebPresentationModeManager {
}
}
}
// listen for pip updates on element
if (this._element !== undefined) {
this._element.onenterpictureinpicture = () => {
this.updatePresentationMode();
};
this._element.onleavepictureinpicture = () => {
this.updatePresentationMode();
};
}
// listen for fullscreen updates on document
if (fullscreenAPI !== undefined) {
document.addEventListener(fullscreenAPI.fullscreenchange_, this.updatePresentationMode);
Expand All @@ -95,7 +87,7 @@ export class WebPresentationModeManager {
let newPresentationMode: PresentationMode = PresentationMode.inline;
if (fullscreenAPI !== undefined && document[fullscreenAPI.fullscreenElement_] !== null) {
newPresentationMode = PresentationMode.fullscreen;
} else if (document.pictureInPictureElement !== null) {
} else if (this._player.presentation.currentMode === 'native-picture-in-picture') {
newPresentationMode = PresentationMode.pip;
}

Expand Down
Loading