|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+function Player(sources) {
|
|
|
2
|
+ this.playlist = sources;
|
|
|
3
|
+ this.current = {};
|
|
|
4
|
+ this.isPlaying = false;
|
|
|
5
|
+ this.player;
|
|
|
6
|
+ this.YTplayer = false;
|
|
|
7
|
+
|
|
|
8
|
+ this.init = function() {
|
|
|
9
|
+ this.loadYTplayer();
|
|
|
10
|
+ this.bindEvents();
|
|
|
11
|
+ console.log('init...');
|
|
|
12
|
+ }
|
|
|
13
|
+
|
|
|
14
|
+ this.bindEvents = function() {
|
|
|
15
|
+ var toggle = document.getElementById('player-toggle');
|
|
|
16
|
+ toggle.addEventListener('click', this.toggle);
|
|
|
17
|
+ var previous = document.getElementById('player-previous');
|
|
|
18
|
+ previous.addEventListener('click', this.previous);
|
|
|
19
|
+ var next = document.getElementById('player-next');
|
|
|
20
|
+ next.addEventListener('click', this.next);
|
|
|
21
|
+ }
|
|
|
22
|
+
|
|
|
23
|
+ this.newSong = function (videoId) {
|
|
|
24
|
+ if (this.YTplayer)
|
|
|
25
|
+ this.YTplayer.parentNode.removeChild(this.YTplayer);
|
|
|
26
|
+ this.YTplayer = new YT.Player('YTplayer', {
|
|
|
27
|
+ height: '0',
|
|
|
28
|
+ width: '0',
|
|
|
29
|
+ videoId: videoId,
|
|
|
30
|
+ playerVars: {
|
|
|
31
|
+
|
|
|
32
|
+ },
|
|
|
33
|
+ events: {
|
|
|
34
|
+ 'onReady': onPlayerReady,
|
|
|
35
|
+ 'onStateChange': onPlayerStateChange
|
|
|
36
|
+ }
|
|
|
37
|
+ });
|
|
|
38
|
+ }
|
|
|
39
|
+
|
|
|
40
|
+ this.loadYTplayer = function() {
|
|
|
41
|
+ var tag = document.createElement('script');
|
|
|
42
|
+ tag.src = "https://www.youtube.com/iframe_api";
|
|
|
43
|
+ var firstScriptTag = document.getElementsByTagName('script')[0];
|
|
|
44
|
+ firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
|
|
|
45
|
+ };
|
|
|
46
|
+
|
|
|
47
|
+ this.seekPosition = function() {};
|
|
|
48
|
+ this.toggle = function() {
|
|
|
49
|
+ if (evaplayer.isPlaying) {
|
|
|
50
|
+ evaplayer.YTplayer.pauseVideo();
|
|
|
51
|
+ } else {
|
|
|
52
|
+ evaplayer.YTplayer.playVideo();
|
|
|
53
|
+ }
|
|
|
54
|
+ evaplayer.isPlaying = !evaplayer.isPlaying;
|
|
|
55
|
+ return evaplayer;
|
|
|
56
|
+ };
|
|
|
57
|
+ this.next = function() {
|
|
|
58
|
+ return
|
|
|
59
|
+ };
|
|
|
60
|
+ this.previous = function() {};
|
|
|
61
|
+ this.init();
|
|
|
62
|
+};
|
|
|
63
|
+
|
|
|
64
|
+function onYouTubeIframeAPIReady() {
|
|
|
65
|
+ evaplayer.newSong('519_pOvP9xs');
|
|
|
66
|
+}
|
|
|
67
|
+
|
|
|
68
|
+function onPlayerReady(event) {
|
|
|
69
|
+ event.target.playVideo();
|
|
|
70
|
+}
|
|
|
71
|
+
|
|
|
72
|
+function onPlayerStateChange(event) {
|
|
|
73
|
+ if (event.data == YT.PlayerState.PLAYING && !evaplayer.isPlaying) {
|
|
|
74
|
+ evaplayer.isPlaying = true;
|
|
|
75
|
+ }
|
|
|
76
|
+}
|