/
index.html
50 lines (43 loc) · 1.18 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<script src='/youtube-player.js'></script>
</head>
<body>
<div id='player-1'></div>
<script>
var player1,
stateNames;
/**
* @see https://developers.google.com/youtube/iframe_api_reference#Events
*/
stateNames = {
'-1': 'unstarted',
0: 'ended',
1: 'playing',
2: 'paused',
3: 'buffering',
5: 'video cued'
};
player1 = YouTubePlayer('player-1', {
videoId: 'M7lc1UVf-VE'
});
player1.on('ready', function () {
console.log('Player1 is ready.');
});
player1
// Play video is a Promise.
// "playVideo" is queued and will execute as soon as player is ready.
.playVideo()
.then(function () {
console.log('Starting to play player1. It will take some time to buffer video before it actually starts playing.');
});
player1.on('stateChange', function (event) {
if (!stateNames[event.data]) {
throw new Error('Unknown state (' + event.data + ').');
}
console.log('State: ' + stateNames[event.data] + ' (' + event.data + ').');
});
</script>
</body>
</html>