-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
28 lines (25 loc) · 912 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const pipBtn = document.querySelector('.btn');
const videoElement = document.querySelector('#video');
async function selectMediaSetream() {
try {
// Request user's display media stream
const mediaStream = await navigator.mediaDevices.getDisplayMedia();
// Set the media stream as the source for the video element
videoElement.srcObject = mediaStream;
videoElement.onloadedmetadata = () => {
videoElement.play();
}
} catch (error) {
// Log any error that occurs during media stream selection
console.log(error);
}
}
pipBtn.addEventListener('click', async (e) => {
e.preventDefault();
pipBtn.disabled = true;
await selectMediaSetream();
await videoElement.play();
// Request Picture-in-Picture mode for the video
await videoElement.requestPictureInPicture();
pipBtn.disabled = false;
})