var Media = function(data) { if(!data) { data = { id: "", type: "null" }; } this.id = data.id; this.type = data.type; this.diff = 0; switch(this.type) { case "yt": this.initYouTube(); break; case "vi": this.initVimeo(); break; case "dm": this.initDailymotion(); break; case "sc": this.initSoundcloud(); break; case "li": this.initLivestream(); break; case "tw": this.initTwitch(); break; case "jt": this.initJustinTV(); break; case "rt": this.initRTMP(); break; case "jw": this.initJWPlayer(); break; case "us": this.initUstream(); break; default: this.nullPlayer(); break; } } Media.prototype.nullPlayer = function() { this.player = null; this.load = function(data) { } this.play = function() { } this.pause = function() { } this.getTime = function(callback) { } this.seek = function(time) { } } Media.prototype.initYouTube = function() { this.removeOld(); this.player = new YT.Player("ytapiplayer", { height: VHEIGHT, width: VWIDTH, videoId: this.id, playerVars: { "autoplay": 1, "controls": 1, }, events: { onReady: function() { socket.emit("playerReady"); }, onStateChange: function(ev) { if(PLAYER.paused && ev.data != YT.PlayerState.PAUSED || !PLAYER.paused && ev.data == YT.PlayerState.PAUSED) { PLAYER.paused = (ev.data == YT.PlayerState.PAUSED); sendVideoUpdate(); } else { PLAYER.paused = (ev.data == YT.PlayerState.PAUSED); } if(LEADER && ev.data == YT.PlayerState.ENDED) { socket.emit("playNext"); } } } }); $("#ytapiplayer").css("border", "none"); this.load = function(data) { if(this.player.loadVideoById) { this.player.loadVideoById(data.id, data.currentTime); this.id = data.id; } } this.pause = function() { this.player.pauseVideo(); } this.play = function() { this.player.playVideo(); } this.getTime = function(callback) { callback(this.player.getCurrentTime()); } this.seek = function(time) { this.player.seekTo(time, true); } } Media.prototype.initVimeo = function() { var iframe = $("