Skip to content

Commit 67fa863

Browse files
committed
feat: add fullscreen API on player element
this is needed for iOS. fix #643
1 parent 9f27791 commit 67fa863

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

examples/vanilla-ts-esm/public/mux-player.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ <h2>On-demand</h2>
5656
});
5757
</script>
5858

59+
<button id="request-fullscreen">
60+
Request Fullscreen
61+
</button>
62+
<script>
63+
document.getElementById('request-fullscreen').addEventListener('click', () => {
64+
const player = document.querySelector('mux-player');
65+
player.requestFullscreen();
66+
});
67+
</script>
68+
69+
<button id="exit-fullscreen">
70+
Exit Fullscreen
71+
</button>
72+
<script>
73+
document.getElementById('exit-fullscreen').addEventListener('click', () => {
74+
const player = document.querySelector('mux-player');
75+
player.exitFullscreen();
76+
});
77+
</script>
78+
5979
<h2>Live</h2>
6080

6181
<mux-player

packages/mux-player/src/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { globalThis, document } from './polyfills';
22
import { MediaController, MediaErrorDialog } from 'media-chrome';
33
import { Attributes as MediaControllerAttributes } from 'media-chrome/dist/media-container.js';
4-
import { MediaUIAttributes } from 'media-chrome/dist/constants.js';
4+
import { MediaUIAttributes, MediaUIEvents } from 'media-chrome/dist/constants.js';
55
import 'media-chrome/dist/experimental/index.js';
66
import { MediaThemeElement } from 'media-chrome/dist/media-theme-element.js';
77
import MuxVideoElement, { MediaError, Attributes as MuxVideoAttributes } from '@mux/mux-video';
@@ -809,6 +809,24 @@ class MuxPlayerElement extends VideoApiElement implements MuxPlayerElement {
809809
this.#render({ [toPropName(attrName)]: newValue });
810810
}
811811

812+
async requestFullscreen(_options?: FullscreenOptions) {
813+
this.mediaController?.dispatchEvent(
814+
new globalThis.CustomEvent(MediaUIEvents.MEDIA_ENTER_FULLSCREEN_REQUEST, {
815+
composed: true,
816+
bubbles: true,
817+
})
818+
);
819+
}
820+
821+
async exitFullscreen() {
822+
this.mediaController?.dispatchEvent(
823+
new globalThis.CustomEvent(MediaUIEvents.MEDIA_EXIT_FULLSCREEN_REQUEST, {
824+
composed: true,
825+
bubbles: true,
826+
})
827+
);
828+
}
829+
812830
get preferCmcd() {
813831
return (this.getAttribute(MuxVideoAttributes.PREFER_CMCD) as ValueOf<CmcdTypes>) ?? undefined;
814832
}

0 commit comments

Comments
 (0)