-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
45 lines (36 loc) · 1.1 KB
/
setup.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!--Selecting button and video in JS-->
const video = document.getElementById('video'); //'video' is the video id in your HTML
const pipButton = document.getElementById('pipButton'); //'pipButton' is the button ID in HTML
<!-- Add functionality to the button if compatible-->
if ('pictureInPictureEnabled' in document) {
pipButton.classList.remove('hidden')
pipButton.disabled = false;
}
<!--Sending API Request-->
if ('pictureInPictureEnabled' in document) {
pipButton.classList.remove('hidden')
pipButton.disabled = false;
pipButton.addEventListener('click', () => {
video.requestPictureInPicture();
});
}
<!--If the video has a disablePictureInPicture attribute, we catch such errors-->
pipButton.addEventListener('click', () => {
video
.requestPictureInPicture()
.catch(error => {
// Error handling
});
});
<!-- Exit PictureInPicture mode-->
pipButton.addEventListener('click', () => {
if (document.pictureInPictureElement) {
document
.exitPictureInPicture()
.catch(error => {
// Error handling
})
} else {
// Request Picture-in-Picture
}
});