This repository was archived by the owner on Apr 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYouTube.html
More file actions
92 lines (84 loc) · 2.62 KB
/
YouTube.html
File metadata and controls
92 lines (84 loc) · 2.62 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>B Minor Mass</title>
<script src="https://www.youtube.com/iframe_api"></script>
<style>
body {
background-color: black;
display: flex;
justify-content: center;
align-items: center;
height: 100vh; /* Make body take the full viewport height */
margin: 0;
}
.video-container {
display: flex;
flex-direction: column;
align-items: center;
width: 1342px;
height: 755px;
justify-content: center;
align-items: center;
}
/* YouTube iframe should take full container size */
#player {
width: 100%;
height: 100%;
}
/* Overlay timer */
#timer {
position: absolute;
top: 10px;
right: 10px;
background: rgba(0, 0, 0, 0.7);
color: white;
font-size: 18px;
font-weight: bold;
padding: 8px 12px;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="video-container">
<div id="player"></div>
<div id="timer">Time Left: --:--</div>
</div>
<script>
let player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
videoId: '3FLbiDrn8IE', // Replace with your video ID
playerVars: { 'modestbranding': 1, 'rel': 0 },
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
updateTimer();
}
function onPlayerStateChange(event) {
if (event.data === YT.PlayerState.PLAYING) {
updateTimer();
}
}
function updateTimer() {
setInterval(() => {
if (player && player.getCurrentTime) {
let currentTime = player.getCurrentTime();
let duration = player.getDuration();
let timeLeft = duration - currentTime;
let minutes = Math.floor(timeLeft / 60);
let seconds = Math.floor(timeLeft % 60);
document.getElementById('timer').innerText = `Time Left: ${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
}
}, 1000);
}
</script>
</body>
</html>