Skip to content

Commit 03dfdcb

Browse files
authored
Merge pull request namyakhan#12 from zrajesh/pic-in-pic-zrajesh
A picture in picture project that lets you share screen and be productive
2 parents ec85c82 + a65fbe4 commit 03dfdcb

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

picture-in-picture/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<link href="https://fonts.googleapis.com/css2?family=Comfortaa:wght@300&family=Lato:wght@300&family=Manrope:wght@300&family=Nunito:wght@300&family=Roboto+Flex:opsz,wght@8..144,200&display=swap" rel="stylesheet">
7+
<title>Picture in Picture</title>
8+
<link rel="stylesheet" href="style.css">
9+
</head>
10+
<body>
11+
<!-- Video -->
12+
<video id="video" controls height="360" width="640" hidden></video>
13+
<div><h1 class="head">Picture in Picture app to share your screen and be productive</h1></div>
14+
<div class="button-container">
15+
<button id="share-btn">SHARE SCREEN</button>
16+
<button id="start-btn" class="hide">START SCREEN</button>
17+
</div>
18+
19+
<script src="script.js"></script>
20+
</body>
21+
</html>

picture-in-picture/script.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const videoTag = document.querySelector('#video');
2+
const startButton = document.querySelector('#start-btn');
3+
const shareButton = document.querySelector('#share-btn');
4+
5+
// Select media stream and play video
6+
async function selectMediaStream() {
7+
try {
8+
const mediaStream = await navigator.mediaDevices.getDisplayMedia();
9+
videoTag.srcObject = mediaStream;
10+
videoTag.onloadedmetadata = () => {
11+
videoTag.play();
12+
};
13+
shareButton.classList.add('hide');
14+
startButton.classList.remove('hide');
15+
} catch (error) {
16+
console.log('ERR: ', error);
17+
}
18+
}
19+
20+
// Share screen to start picture in picture
21+
shareButton.addEventListener('click', async () => {
22+
selectMediaStream();
23+
});
24+
25+
startButton.addEventListener('click', async () => {
26+
startButton.disabled = true;
27+
// Start picture in picture
28+
await videoTag.requestPictureInPicture();
29+
startButton.disabled = false;
30+
shareButton.classList.remove('hide');
31+
startButton.classList.add('hide');
32+
});

picture-in-picture/style.css

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
* {
2+
margin: 0;
3+
padding: 0;
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
background: #2D364E;
9+
color: #fff;
10+
font-family: 'Comfortaa', cursive;
11+
font-family: 'Lato', sans-serif;
12+
}
13+
14+
.head {
15+
display: flex;
16+
justify-content: center;
17+
margin-top: 80px;
18+
}
19+
20+
.button-container {
21+
display: flex;
22+
justify-content: center;
23+
align-items: center;
24+
height: 60vh;
25+
gap: 20px;
26+
padding: 10px;
27+
border-radius: 7px;
28+
}
29+
30+
button {
31+
cursor: pointer;
32+
outline: none;
33+
font-size: 25px;
34+
color: white;
35+
border-radius: 7px;
36+
padding: 5px 10px;
37+
}
38+
39+
#start-btn {
40+
background: #1DA1F2;
41+
border: 2px solid #1DA1F2;
42+
}
43+
44+
#share-btn {
45+
background-color: #46A74E;
46+
border: 2px solid #46A74E;
47+
}
48+
49+
#start-btn:hover {
50+
background: #1da0f2c7;
51+
}
52+
53+
#share-btn:hover {
54+
background-color: #46a74ed8;
55+
}
56+
57+
.hide {
58+
display: none;
59+
}

0 commit comments

Comments
 (0)