-
Notifications
You must be signed in to change notification settings - Fork 0
/
dyft.js
69 lines (48 loc) · 1.46 KB
/
dyft.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// 2. This code loads the IFrame Player API code asynchronously.
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. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player("player", {
host: "https://www.youtube.com",
/* no need to specify player
size here since it is handled
by the player-size div */
videoId: "7YZCUpnaTfg",
playerVars: {
enablejsapi: 1,
playsinline: 1,
start: 0,
disablekb: 0
},
events: {
onStateChange: onPlayerStateChange
}
});
}
function onPlayerStateChange(event) {
console.log("player state: " + player.getPlayerState());
}
function updateVideoId() {
let videoId = document.getElementById("videoId").value;
const myArray = videoId.split("youtu.be/");
var final = myArray[1];
player.loadVideoById(final, -1);
}
function stopVideo() {
player.stopVideo();
}
function openFullscreen() {
elem = document.getElementById("player-size");
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.webkitRequestFullscreen) { /* Safari */
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) { /* IE11 */
elem.msRequestFullscreen();
}
}