-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
31 lines (26 loc) · 813 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
28
29
30
31
const videoElement = document.getElementById("video");
const button = document.getElementById("button");
// 1: prompt the user to select media stream
// 2: pass the video element
// 3: start {play}
let pictureInPictureWindow = null;
const selectMediaStream = async () => {
try {
const mediaStream = await navigator.mediaDevices.getDisplayMedia();
videoElement.srcObject = mediaStream;
videoElement.onloadedmetadata = () => {
videoElement.play();
};
} catch (error) {
console.log("oops, the was an error", error);
}
};
button.addEventListener("click", async () => {
// Disable button
button.disabled = true;
// start Pic to Pic
pictureInPictureWindow = await videoElement.requestPictureInPicture();
// Reset button
button.disabled = false;
});
selectMediaStream();