From 7ecbddfca1b43f480542de8ba02e9660b6b4831e Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Tue, 31 Dec 2013 00:14:03 -0500 Subject: [PATCH 1/5] Start working on flat volumes --- www/assets/js/player.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/www/assets/js/player.js b/www/assets/js/player.js index 63bd2a2a..0a94fde9 100644 --- a/www/assets/js/player.js +++ b/www/assets/js/player.js @@ -105,6 +105,20 @@ var YouTubePlayer = function (data) { if(self.player && self.player.seekTo) self.player.seekTo(time, true); }; + + self.getVolume = function () { + if (!self.player || !self.player.getVolume || !self.player.isMuted) { + return NaN; + } + + return self.player.isMuted() ? 0 : self.player.getVolume()/100; + }; + + self.setVolume = function (vol) { + if (self.player && self.player.setVolume) { + self.player.setVolume(vol * 100); + } + }; }; var VimeoPlayer = function (data) { From d7011029b865df12c73041786db66b67f5e3f01c Mon Sep 17 00:00:00 2001 From: calzoneman Date: Tue, 31 Dec 2013 11:09:30 -0500 Subject: [PATCH 2/5] Continue working on flat volumes --- www/assets/js/callbacks.js | 8 +- www/assets/js/data.js | 7 +- www/assets/js/player.js | 327 +++++++++++++++++++++++++------------ 3 files changed, 232 insertions(+), 110 deletions(-) diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 4bd7f856..be1732b9 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -1,5 +1,4 @@ /* -return null; The MIT License (MIT) Copyright (c) 2013 Calvin Montgomery @@ -1010,6 +1009,13 @@ Callbacks = { }, changeMedia: function(data) { + if (PLAYER) { + console.log('getting volume for', PLAYER.type); + PLAYER.getVolume(function (v) { + VOLUME = v; + }); + } + if(CHANNEL.opts.allow_voteskip) $("#voteskip").attr("disabled", false); diff --git a/www/assets/js/data.js b/www/assets/js/data.js index 33db153d..0733a562 100644 --- a/www/assets/js/data.js +++ b/www/assets/js/data.js @@ -1,11 +1,11 @@ /* The MIT License (MIT) Copyright (c) 2013 Calvin Montgomery - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ @@ -36,6 +36,7 @@ var CHANNEL = { }; var PLAYER = false; +var VOLUME = 1; var VIDEOQUALITY = false; var FLUIDLAYOUT = false; var VWIDTH; diff --git a/www/assets/js/player.js b/www/assets/js/player.js index 0a94fde9..159da347 100644 --- a/www/assets/js/player.js +++ b/www/assets/js/player.js @@ -43,6 +43,7 @@ var YouTubePlayer = function (data) { }, events: { onReady: function () { + PLAYER.setVolume(VOLUME); }, onStateChange: function (ev) { if(PLAYER.paused && ev.data != YT.PlayerState.PAUSED || @@ -106,12 +107,16 @@ var YouTubePlayer = function (data) { self.player.seekTo(time, true); }; - self.getVolume = function () { + self.getVolume = function (cb) { if (!self.player || !self.player.getVolume || !self.player.isMuted) { - return NaN; + return; } - return self.player.isMuted() ? 0 : self.player.getVolume()/100; + // YouTube's API is strange in the sense that getVolume() returns + // the regular (unmuted) volume even if it is muted... + // YouTube's volume is 0..100, normalize it to 0..1 + var vol = self.player.isMuted() ? 0 : (self.player.getVolume() / 100); + cb(vol); }; self.setVolume = function (vol) { @@ -161,6 +166,8 @@ var VimeoPlayer = function (data) { if(CLIENT.leader) sendVideoUpdate(); }); + + self.setVolume(VOLUME); }.bind(self)); }; @@ -199,6 +206,14 @@ var VimeoPlayer = function (data) { if(self.player && self.player.api) self.player.api("seekTo", time); }; + + self.getVolume = function (cb) { + self.player.api("getVolume", cb); + }; + + self.setVolume = function (vol) { + self.player.api("setVolume", vol); + }; }); }; @@ -258,6 +273,8 @@ var VimeoFlashPlayer = function (data) { if(CLIENT.leader) sendVideoUpdate(); }); + + self.setVolume(VOLUME); }); }); }; @@ -295,6 +312,14 @@ var VimeoFlashPlayer = function (data) { if(self.player.api_seekTo); self.player.api_seekTo(time); }; + + self.getVolume = function (cb) { + cb(self.player.api_getVolume()); + }; + + self.setVolume = function (vol) { + self.player.api_setVolume(vol); + }; }; var DailymotionPlayer = function (data) { @@ -328,14 +353,17 @@ var DailymotionPlayer = function (data) { if(CLIENT.leader) sendVideoUpdate(); }); + + self.setVolume(VOLUME); }); }); self.load = function (data) { self.videoId = data.id; self.videoLength = data.seconds; - if(self.player && self.player.api) + if (self.player && self.player.api) { self.player.api("load", data.id); + } }; self.pause = function () { @@ -361,6 +389,14 @@ var DailymotionPlayer = function (data) { if(self.player && self.player.api) self.player.api("seek", seconds); }; + + self.getVolume = function (cb) { + cb(self.player.volume); + }; + + self.setVolume = function (vol) { + self.player.api("volume", vol); + }; }; var SoundcloudPlayer = function (data) { @@ -382,7 +418,7 @@ var SoundcloudPlayer = function (data) { volslider.slider({ range: "min", - value: 100, + value: VOLUME * 100, stop: function (event, ui) { self.player.setVolume(ui.value); } @@ -410,14 +446,17 @@ var SoundcloudPlayer = function (data) { socket.emit("playNext"); } }); + + self.setVolume(VOLUME); }.bind(self)); }); self.load = function (data) { self.videoId = data.id; self.videoLength = data.seconds; - if(self.player && self.player.load) + if(self.player && self.player.load) { self.player.load(data.id, { auto_play: true }); + } }; self.pause = function () { @@ -449,6 +488,18 @@ var SoundcloudPlayer = function (data) { if(self.player && self.player.seekTo) self.player.seekTo(seconds * 1000); }; + + self.getVolume = function (cb) { + self.player.getVolume(function (v) { + // Soundcloud volume is 0..100, normalize to 0..1 + v /= 100; + cb(v); + }); + }; + + self.setVolume = function (vol) { + self.player.setVolume(vol * 100); + }; }; var LivestreamPlayer = function (data) { @@ -488,6 +539,10 @@ var LivestreamPlayer = function (data) { self.getTime = function () { }; self.seek = function () { }; + + self.getVolume = function () { }; + + self.setVolume = function () { }; }; var TwitchTVPlayer = function (data) { @@ -503,102 +558,7 @@ var TwitchTVPlayer = function (data) { allowNetworking: "all", movie: "http://www.twitch.tv/widgets/live_embed_player.swf", id: "live_embed_player_flash", - flashvars: "hostname=www.twitch.tv&channel="+self.videoId+"&auto_play=true&start_volume=100" - }; - swfobject.embedSWF(url, - "ytapiplayer", - VWIDTH, VHEIGHT, - "8", - null, null, - params, - {} - ); - }; - - waitUntilDefined(window, "swfobject", function () { - self.init(); - }); - - self.load = function (data) { - self.videoId = data.id; - self.videoLength = data.seconds; - self.init(); - }; - - self.pause = function () { }; - - self.play = function () { }; - - self.isPaused = function () { }; - - self.getTime = function () { }; - - self.seek = function () { }; -}; - -var JustinTVPlayer = function (data) { - removeOld(); - var self = this; - self.videoId = data.id; - self.videoLength = data.seconds; - self.init = function () { - var prto = location.protocol; - var url = "http://www.justin.tv/widgets/live_embed_player.swf?channel="+self.videoId; - var params = { - allowFullScreen: "true", - allowScriptAccess: "always", - allowNetworking: "all", - movie: "http://www.justin.tv/widgets/live_embed_player.swf", - id: "live_embed_player_flash", - flashvars: "hostname=www.justin.tv&channel="+self.videoId+"&auto_play=true&start_volume=100" - }; - swfobject.embedSWF(url, - "ytapiplayer", - VWIDTH, VHEIGHT, - "8", - null, null, - params, - {} - ); - }; - - waitUntilDefined(window, "swfobject", function () { - self.init(); - }); - - self.load = function (data) { - self.videoId = data.id; - self.videoLength = data.seconds; - self.init(); - }; - - self.pause = function () { }; - - self.play = function () { }; - - self.isPaused = function () { }; - - self.getTime = function () { }; - - self.seek = function () { }; -}; - -var RTMPPlayer = function (data) { - removeOld(); - var self = this; - self.videoId = data.id; - self.videoLength = data.seconds; - self.init = function () { - var prto = location.protocol; - var url = prto+"//fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf"; - var src = encodeURIComponent(self.videoId); - var params = { - allowFullScreen: "true", - allowScriptAccess: "always", - allowNetworking: "all", - wMode: "direct", - movie: prto+"//fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf", - flashvars: "src="+src+"&streamType=live&autoPlay=true" + flashvars: "hostname=www.twitch.tv&channel="+self.videoId+"&auto_play=true&start_volume=" + VOLUME }; swfobject.embedSWF(url, "ytapiplayer", @@ -629,6 +589,122 @@ var RTMPPlayer = function (data) { self.getTime = function () { }; self.seek = function () { }; + + self.getVolume = function () { }; + + self.setVolume = function () { }; +}; + +var JustinTVPlayer = function (data) { + removeOld(); + var self = this; + self.videoId = data.id; + self.videoLength = data.seconds; + self.init = function () { + var prto = location.protocol; + var url = "http://www.justin.tv/widgets/live_embed_player.swf?channel="+self.videoId; + var params = { + allowFullScreen: "true", + allowScriptAccess: "always", + allowNetworking: "all", + movie: "http://www.justin.tv/widgets/live_embed_player.swf", + id: "live_embed_player_flash", + flashvars: "hostname=www.justin.tv&channel="+self.videoId+"&auto_play=true&start_volume=" + VOLUME + }; + swfobject.embedSWF(url, + "ytapiplayer", + VWIDTH, VHEIGHT, + "8", + null, null, + params, + {} + ); + }; + + waitUntilDefined(window, "swfobject", function () { + self.init(); + }); + + self.load = function (data) { + self.videoId = data.id; + self.videoLength = data.seconds; + self.init(); + }; + + self.pause = function () { }; + + self.play = function () { }; + + self.isPaused = function () { }; + + self.getTime = function () { }; + + self.seek = function () { }; + + self.getVolume = function () { }; + + self.setVolume = function () { }; +}; + +function rtmpEventHandler(id, ev, data) { + if (ev === "volumechange") { + PLAYER.volume = (data.muted ? 0 : data.volume); + } +} + +var RTMPPlayer = function (data) { + removeOld(); + var self =this; + self.volume = VOLUME; + self.videoId = data.id; + self.videoLength = data.seconds; + self.init = function () { + var prto = location.protocol; + var url = prto+"//fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf"; + var src = encodeURIComponent(self.videoId); + var params = { + allowFullScreen: "true", + allowScriptAccess: "always", + allowNetworking: "all", + wMode: "direct", + movie: prto+"//fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf", + flashvars: "src="+src+"&streamType=live&javascriptCallbackFunction=rtmpEventHandler&autoPlay=true&volume=" + VOLUME + }; + swfobject.embedSWF(url, + "ytapiplayer", + VWIDTH, VHEIGHT, + "8", + null, null, + params, + {} + ); + }; + + waitUntilDefined(window, "swfobject", function () { + self.init(); + }); + + self.load = function (data) { + self.videoId = data.id; + self.videoLength = data.seconds; + self.init(); + }; + + self.pause = function () { }; + + self.play = function () { }; + + self.isPaused = function () { }; + + self.getTime = function () { }; + + self.seek = function () { }; + + self.getVolume = function (cb) { + cb(self.volume); + }; + + self.setVolume = function () { }; }; var JWPlayer = function (data) { @@ -644,7 +720,6 @@ var JWPlayer = function (data) { height: VHEIGHT, autostart: true }); - jwplayer().onPlay(function() { self.paused = false; if(CLIENT.leader) @@ -658,6 +733,7 @@ var JWPlayer = function (data) { jwplayer().onComplete(function() { socket.emit("playNext"); }); + self.setVolume(VOLUME); }; waitUntilDefined(window, "jwplayer", function () { self.init(); }); @@ -694,6 +770,14 @@ var JWPlayer = function (data) { if(jwplayer) jwplayer().seek(time); }; + + self.getVolume = function (cb) { + cb(jwplayer().getVolume() / 100); + }; + + self.setVolume = function (vol) { + jwplayer().setVolume(vol * 100); + }; }; var UstreamPlayer = function (data) { @@ -711,7 +795,7 @@ var UstreamPlayer = function (data) { iframe.attr("scrolling", "no"); iframe.css("border", "none"); }; - + self.init(); self.load = function (data) { @@ -729,6 +813,10 @@ var UstreamPlayer = function (data) { self.getTime = function () { }; self.seek = function () { }; + + self.getVolume = function () { }; + + self.setVolume = function () { }; }; var ImgurPlayer = function (data) { @@ -762,6 +850,10 @@ var ImgurPlayer = function (data) { self.getTime = function () { }; self.seek = function () { }; + + self.getVolume = function () { }; + + self.setVolume = function () { }; }; var CustomPlayer = function (data) { @@ -799,6 +891,10 @@ var CustomPlayer = function (data) { self.getTime = function () { }; self.seek = function () { }; + + self.getVolume = function () { }; + + self.setVolume = function () { }; }; var GoogleDocsPlayer = function (data) { @@ -816,6 +912,7 @@ var GoogleDocsPlayer = function (data) { $("", p).appendTo(self.player); }); removeOld($(self.player)); + self.setVolume(VOLUME); }; self.init(data); @@ -852,13 +949,31 @@ var GoogleDocsPlayer = function (data) { if(self.player && self.player.seekTo) self.player.seekTo(time, true); }; + + self.getVolume = function (cb) { + if (!self.player || !self.player.getVolume || !self.player.isMuted) { + return; + } + + // YouTube's API is strange in the sense that getVolume() returns + // the regular (unmuted) volume even if it is muted... + // YouTube's volume is 0..100, normalize it to 0..1 + var vol = self.player.isMuted() ? 0 : (self.player.getVolume() / 100); + cb(vol); + }; + + self.setVolume = function (vol) { + if (self.player && self.player.setVolume) { + self.player.setVolume(vol * 100); + } + }; }; function handleMediaUpdate(data) { // Don't update if the position is past the video length, but // make an exception when the video length is 0 seconds if (typeof PLAYER.videoLength === "number") { - if (PLAYER.videoLength > 0 && + if (PLAYER.videoLength > 0 && data.currentTime > PLAYER.videoLength) { return; } @@ -889,7 +1004,7 @@ function handleMediaUpdate(data) { }, tm); return; } - + // Don't synch if leader or synch disabled if(CLIENT.leader || !USEROPTS.synch) return; From c136d566fedf041698418f0fb039f488fab2ac64 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Wed, 1 Jan 2014 23:59:53 -0500 Subject: [PATCH 3/5] Fix some volume sync issues with youtube and soundcloud --- www/assets/js/player.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/www/assets/js/player.js b/www/assets/js/player.js index 159da347..72d9ebd7 100644 --- a/www/assets/js/player.js +++ b/www/assets/js/player.js @@ -121,6 +121,9 @@ var YouTubePlayer = function (data) { self.setVolume = function (vol) { if (self.player && self.player.setVolume) { + if (vol > 0) { + self.player.unMute(); + } self.player.setVolume(vol * 100); } }; @@ -401,6 +404,9 @@ var DailymotionPlayer = function (data) { var SoundcloudPlayer = function (data) { var self = this; + // The getVolume function on their widget throws TypeErrors + // Go figure + self.soundcloudIsSeriouslyFuckingBroken = VOLUME; self.videoId = data.id; self.videoLength = data.seconds; waitUntilDefined(window, "SC", function () { @@ -421,6 +427,7 @@ var SoundcloudPlayer = function (data) { value: VOLUME * 100, stop: function (event, ui) { self.player.setVolume(ui.value); + self.soundcloudIsSeriouslyFuckingBroken = ui.value / 100; } }); @@ -435,19 +442,24 @@ var SoundcloudPlayer = function (data) { sendVideoUpdate(); }); - self.player.bind(SC.Widget.Events.PLAY, function () { - PLAYER.paused = false; - if(CLIENT.leader) - sendVideoUpdate(); - }); - self.player.bind(SC.Widget.Events.FINISH, function () { if(CLIENT.leader) { socket.emit("playNext"); } }); - self.setVolume(VOLUME); + self.player.bind(SC.Widget.Events.PLAY, function () { + PLAYER.paused = false; + if(CLIENT.leader) + sendVideoUpdate(); + }); + + // THAT'S RIGHT, YOU CAN'T SET THE VOLUME BEFORE IT STARTS PLAYING + var soundcloudNeedsToFuckingFixTheirPlayer = function () { + self.setVolume(VOLUME); + self.player.unbind(SC.Widget.Events.PLAY_PROGRESS); + }; + self.player.bind(SC.Widget.Events.PLAY_PROGRESS, soundcloudNeedsToFuckingFixTheirPlayer); }.bind(self)); }); @@ -490,11 +502,7 @@ var SoundcloudPlayer = function (data) { }; self.getVolume = function (cb) { - self.player.getVolume(function (v) { - // Soundcloud volume is 0..100, normalize to 0..1 - v /= 100; - cb(v); - }); + cb(self.soundcloudIsSeriouslyFuckingBroken); }; self.setVolume = function (vol) { From afe14c2128b58bbc29eb83707cea34f6330ca420 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Thu, 2 Jan 2014 00:13:45 -0500 Subject: [PATCH 4/5] Save volume in localStorage --- www/assets/js/callbacks.js | 1 + www/assets/js/data.js | 3 ++- www/assets/js/player.js | 8 ++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index be1732b9..75b53c8a 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -1013,6 +1013,7 @@ Callbacks = { console.log('getting volume for', PLAYER.type); PLAYER.getVolume(function (v) { VOLUME = v; + setOpt("volume", VOLUME); }); } diff --git a/www/assets/js/data.js b/www/assets/js/data.js index 0733a562..ce88422c 100644 --- a/www/assets/js/data.js +++ b/www/assets/js/data.js @@ -36,7 +36,6 @@ var CHANNEL = { }; var PLAYER = false; -var VOLUME = 1; var VIDEOQUALITY = false; var FLUIDLAYOUT = false; var VWIDTH; @@ -124,6 +123,8 @@ var USEROPTS = { secure_connection : getOrDefault("secure_connection", false) }; +var VOLUME = getOrDefault("volume", 1); + var NO_WEBSOCKETS = USEROPTS.altsocket; var Rank = { diff --git a/www/assets/js/player.js b/www/assets/js/player.js index 72d9ebd7..60838da7 100644 --- a/www/assets/js/player.js +++ b/www/assets/js/player.js @@ -174,8 +174,6 @@ var VimeoPlayer = function (data) { }.bind(self)); }; - self.init(); - self.load = function (data) { self.videoId = data.id; self.videoLength = data.seconds; @@ -217,6 +215,8 @@ var VimeoPlayer = function (data) { self.setVolume = function (vol) { self.player.api("setVolume", vol); }; + + self.init(); }); }; @@ -282,8 +282,6 @@ var VimeoFlashPlayer = function (data) { }); }; - self.init(); - self.load = function (data) { self.videoId = data.id; self.videoLength = data.seconds; @@ -323,6 +321,8 @@ var VimeoFlashPlayer = function (data) { self.setVolume = function (vol) { self.player.api_setVolume(vol); }; + + self.init(); }; var DailymotionPlayer = function (data) { From b243f8bc7e8b73c54edfede3b7e7b729ad87526c Mon Sep 17 00:00:00 2001 From: calzoneman Date: Thu, 2 Jan 2014 10:04:16 -0500 Subject: [PATCH 5/5] Fix soundcloud/soundcloud transition --- www/assets/js/callbacks.js | 1 - www/assets/js/player.js | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 75b53c8a..b8ed06f3 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -1010,7 +1010,6 @@ Callbacks = { changeMedia: function(data) { if (PLAYER) { - console.log('getting volume for', PLAYER.type); PLAYER.getVolume(function (v) { VOLUME = v; setOpt("volume", VOLUME); diff --git a/www/assets/js/player.js b/www/assets/js/player.js index 60838da7..4458fa0a 100644 --- a/www/assets/js/player.js +++ b/www/assets/js/player.js @@ -468,6 +468,11 @@ var SoundcloudPlayer = function (data) { self.videoLength = data.seconds; if(self.player && self.player.load) { self.player.load(data.id, { auto_play: true }); + var soundcloudNeedsToFuckingFixTheirPlayer = function () { + self.setVolume(VOLUME); + self.player.unbind(SC.Widget.Events.PLAY_PROGRESS); + }; + self.player.bind(SC.Widget.Events.PLAY_PROGRESS, soundcloudNeedsToFuckingFixTheirPlayer); } };