-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Expand file tree
/
Copy pathyoutube_embed.html
More file actions
104 lines (103 loc) · 4.3 KB
/
youtube_embed.html
File metadata and controls
104 lines (103 loc) · 4.3 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
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html>
<head>
<style>
body { margin: 0; width:100%%; height:100%%; background-color:#000; }
html { width:100%%; height:100%%; background-color:#000; }
.embed-container iframe,
.embed-container object,
.embed-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%% !important;
height: 100%% !important;
}
</style>
</head>
<body>
<div class="embed-container">
<div id="player"></div>
</div>
<script src="https://www.youtube.com/iframe_api"></script>
<script>
var player;
var posted = false;
YT.ready(function() {
player = new YT.Player("player", {
"width": "100%%",
"events": {
"onReady": "onReady",
"onError": "onError",
"onStateChange": "onStateChange",
},
"videoId": "%1$s",
"height": "100%%",
"playerVars": {
"start": %2$d,
"rel": 1,
"showinfo": 0,
"modestbranding": 0,
"iv_load_policy": 3,
"autohide": 1,
"autoplay": 1,
"cc_load_policy": 1,
"playsinline": 1,
"controls": 0
}
});
player.setSize(window.innerWidth, window.innerHeight);
});
function onError(event) {
if (window.YoutubeProxy !== undefined) {
YoutubeProxy.onPlayerError(event.data);
}
if (!posted) {
if (window.YoutubeProxy !== undefined) {
YoutubeProxy.onPlayerLoaded();
}
posted = true;
}
}
function onStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !posted) {
if (window.YoutubeProxy !== undefined) {
YoutubeProxy.onPlayerLoaded();
}
posted = true;
}
if (window.YoutubeProxy !== undefined) {
YoutubeProxy.onPlayerStateChange(event.data);
}
}
function onReady(event) {
playVideo();
if (window.YoutubeProxy !== undefined) {
YoutubeProxy.onPlayerNotifyDuration(player.getDuration());
}
}
function playVideo() {
player.playVideo();
}
function pauseVideo() {
player.pauseVideo();
}
function seekTo(time, seekAhead) {
player.seekTo(time, seekAhead);
}
function setPlaybackSpeed(speed) {
player.setPlaybackRate(speed);
}
function pollPosition() {
if (window.YoutubeProxy !== undefined) {
YoutubeProxy.onPlayerNotifyCurrentPosition(player.getCurrentTime());
YoutubeProxy.onPlayerNotifyBufferedPosition(player.getVideoLoadedFraction());
}
}
window.onresize = function() {
player.setSize(window.innerWidth, window.innerHeight);
playVideo();
}
</script>
</body>
</html>