-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtestYoutubeApi.js
More file actions
87 lines (81 loc) · 2.68 KB
/
Copy pathtestYoutubeApi.js
File metadata and controls
87 lines (81 loc) · 2.68 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
//// Load the IFrame Player API code asynchronously.
//var tag = document.createElement('script');
//tag.src = "https://www.youtube.com/player_api";
//var firstScriptTag = document.getElementsByTagName('script')[0];
//firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
//
//// Replace the 'ytplayer' element with an <iframe> and
//// YouTube player after the API code downloads.
//var player;
//function onYouTubePlayerAPIReady() {
// player = new YT.Player('player', {
// width: '600',
// height: '400',
// videoId: 'JidJV1ue1lI',
// events: {
// 'onError': onYoutubeError,
// 'onReady': onYoutubeReady
// },
// playerVars: {
// fs: 0,
// iv_load_policy: 3,
// rel: 0
// }
// });
//}
//
//
//function onYoutubeError(event) {
// console.log("youtube error:");
// console.log(event);
// if(event.data == 100 || event.data == 101 || event.data == 150) {
// //not found, or not allowed to be embedded. hopefully the dj server checked for this, but if not, we skip it now.
//
// nextSong(true);
// }
//
//}
//
//function onYoutubeReady(event) {
// console.log("youtube became ready");
// youtubeBecameReady = true;
//}
// 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() {
console.log("onYouTubeIframeAPIReady");
player = new YT.Player('player', {
height: '790',
width: '940',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
console.log("onPlayerReady");
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
console.log("onPlayerStateChange");
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}