From 69550c7a513ca1c82d9f68a805c6fba93d601c6c Mon Sep 17 00:00:00 2001 From: calzoneman Date: Tue, 14 May 2013 11:19:03 -0400 Subject: [PATCH] Fix errors when video is hidden --- www/assets/js/client.js | 30 ++++++++---------------------- www/assets/js/media.js | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/www/assets/js/client.js b/www/assets/js/client.js index dfd54843..2b94068a 100644 --- a/www/assets/js/client.js +++ b/www/assets/js/client.js @@ -10,8 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ var LEADER = false; -var PLAYER = false; -var MEDIATYPE = "yt"; +var PLAYER = new Media(); +var MEDIATYPE = "null"; var POSITION = -1; var RANK = 0; var OPENQUEUE = false; @@ -138,28 +138,14 @@ else { }); } -//socket.on("connect", function() { -// socket.emit("joinChannel", { -// name: CHANNEL -// }); -// if(uname && session) { -// socket.emit("login", { -// name: uname, -// session: session -// }); -// } -// $("
").addClass("server-msg-reconnect") -// .text("Connected") -// .appendTo($("#messagebuffer")); -// $("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight")); -//}); - // Load the youtube iframe API -var tag = document.createElement("script"); -tag.src = "http://www.youtube.com/iframe_api"; -var firstScriptTag = document.getElementsByTagName("script")[0]; -firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); +if(!USEROPTS.hidevid) { + var tag = document.createElement("script"); + tag.src = "http://www.youtube.com/iframe_api"; + var firstScriptTag = document.getElementsByTagName("script")[0]; + firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); +} var sendVideoUpdate = function() { } setInterval(function() { diff --git a/www/assets/js/media.js b/www/assets/js/media.js index 8e59a442..1474b999 100644 --- a/www/assets/js/media.js +++ b/www/assets/js/media.js @@ -1,4 +1,10 @@ var Media = function(data) { + if(!data) { + data = { + id: "", + type: "null" + }; + } this.id = data.id; this.type = data.type; this.diff = 0; @@ -29,10 +35,20 @@ var Media = function(data) { this.initJWPlayer(); 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", { @@ -397,6 +413,9 @@ Media.prototype.removeOld = function() { } Media.prototype.hide = function() { + if(this.type == "null") { + return; + } this.getTime(function(seconds) { this.time = seconds; this.hidden = $("#ytapiplayer").detach(); @@ -404,6 +423,9 @@ Media.prototype.hide = function() { } Media.prototype.unhide = function() { + if(this.type == "null") { + return; + } this.hidden.appendTo($("#videodiv")); var data = { id: this.id,