Continue working on flat volumes

This commit is contained in:
calzoneman 2013-12-31 11:09:30 -05:00
parent 7ecbddfca1
commit d7011029b8
3 changed files with 232 additions and 110 deletions

View File

@ -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);

View File

@ -36,6 +36,7 @@ var CHANNEL = {
};
var PLAYER = false;
var VOLUME = 1;
var VIDEOQUALITY = false;
var FLUIDLAYOUT = false;
var VWIDTH;

View File

@ -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,7 +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"
flashvars: "hostname=www.twitch.tv&channel="+self.videoId+"&auto_play=true&start_volume=" + VOLUME
};
swfobject.embedSWF(url,
"ytapiplayer",
@ -534,6 +589,10 @@ var TwitchTVPlayer = function (data) {
self.getTime = function () { };
self.seek = function () { };
self.getVolume = function () { };
self.setVolume = function () { };
};
var JustinTVPlayer = function (data) {
@ -550,7 +609,7 @@ var JustinTVPlayer = function (data) {
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"
flashvars: "hostname=www.justin.tv&channel="+self.videoId+"&auto_play=true&start_volume=" + VOLUME
};
swfobject.embedSWF(url,
"ytapiplayer",
@ -581,11 +640,22 @@ var JustinTVPlayer = function (data) {
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;
var self =this;
self.volume = VOLUME;
self.videoId = data.id;
self.videoLength = data.seconds;
self.init = function () {
@ -598,7 +668,7 @@ var RTMPPlayer = function (data) {
allowNetworking: "all",
wMode: "direct",
movie: prto+"//fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf",
flashvars: "src="+src+"&streamType=live&autoPlay=true"
flashvars: "src="+src+"&streamType=live&javascriptCallbackFunction=rtmpEventHandler&autoPlay=true&volume=" + VOLUME
};
swfobject.embedSWF(url,
"ytapiplayer",
@ -629,6 +699,12 @@ var RTMPPlayer = function (data) {
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) {
@ -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) {
$("<param/>", p).appendTo(self.player);
});
removeOld($(self.player));
self.setVolume(VOLUME);
};
self.init(data);
@ -852,6 +949,24 @@ 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) {