-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
49 lines (47 loc) · 1.88 KB
/
index.html
File metadata and controls
49 lines (47 loc) · 1.88 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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>YouTube Relay</title>
<style>
/* Ensures the player fills the entire iframe window */
body, html { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; }
#player { width: 100%; height: 100%; }
</style>
</head>
<body>
<div id="player"></div>
<script>
// 1. Get the video ID from the URL query parameter
const urlParams = new URLSearchParams(window.location.search);
const videoId = urlParams.get('videoId');
// 2. Ensure the YouTube IFrame API script is loaded
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. The API will call this function when it's ready
var player;
function onYouTubeIframeAPIReady() {
// Note: The player is created on the relay page's origin (https://yourdomain.com),
// which satisfies YouTube's security requirements.
player = new YT.Player('player', {
videoId: videoId,
playerVars: {
'rel': 0, // Disable related videos
'autoplay': 0, // Optional: Start playing immediately
// *** You DO NOT need to set the 'origin' parameter here! ***
// The origin is automatically determined as the host of this page.
},
events: {
'onReady': onPlayerReady
}
});
}
function onPlayerReady(event) {
// Optional: Start playback if 'autoplay' failed
// event.target.playVideo();
}
</script>
</body>
</html>