| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- function Player(sources) {
- this.playlist = sources;
- this.current = {};
- this.isPlaying = false;
- this.player;
- this.YTplayer = false;
-
- this.init = function() {
- this.loadYTplayer();
- this.bindEvents();
- console.log('init...');
- }
-
- this.bindEvents = function() {
- var toggle = document.getElementById('player-toggle');
- toggle.addEventListener('click', this.toggle);
- var previous = document.getElementById('player-previous');
- previous.addEventListener('click', this.previous);
- var next = document.getElementById('player-next');
- next.addEventListener('click', this.next);
- }
-
- this.newSong = function (videoId) {
- if (this.YTplayer)
- this.YTplayer.parentNode.removeChild(this.YTplayer);
- this.YTplayer = new YT.Player('YTplayer', {
- height: '0',
- width: '0',
- videoId: videoId,
- playerVars: {
-
- },
- events: {
- 'onReady': onPlayerReady,
- 'onStateChange': onPlayerStateChange
- }
- });
- }
-
- this.loadYTplayer = function() {
- var tag = document.createElement('script');
- tag.src = "https://www.youtube.com/iframe_api";
- var firstScriptTag = document.getElementsByTagName('script')[0];
- firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
- };
-
- this.seekPosition = function() {};
- this.toggle = function() {
- if (evaplayer.isPlaying) {
- evaplayer.YTplayer.pauseVideo();
- } else {
- evaplayer.YTplayer.playVideo();
- }
- evaplayer.isPlaying = !evaplayer.isPlaying;
- return evaplayer;
- };
- this.next = function() {
- return
- };
- this.previous = function() {};
- this.init();
- };
-
- function onYouTubeIframeAPIReady() {
- evaplayer.newSong('519_pOvP9xs');
- }
-
- function onPlayerReady(event) {
- event.target.playVideo();
- }
-
- function onPlayerStateChange(event) {
- if (event.data == YT.PlayerState.PLAYING && !evaplayer.isPlaying) {
- evaplayer.isPlaying = true;
- }
- }
|