From b279a411228681f3426cd6fb7c0d1e1421c16307 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Fri, 19 Jun 2015 22:12:48 -0400 Subject: [PATCH] Add RTMP player --- player/rtmp.coffee | 26 ++++++++++++++++++++++++++ player/update.coffee | 1 + www/js/player-new.js | 41 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 player/rtmp.coffee diff --git a/player/rtmp.coffee b/player/rtmp.coffee new file mode 100644 index 00000000..c8508a0c --- /dev/null +++ b/player/rtmp.coffee @@ -0,0 +1,26 @@ +window.rtmpEventHandler = (id, event, data) -> + if event == 'volumechange' + PLAYER.volume = if data.muted then 0 else data.volume + +window.RTMPPlayer = class RTMPPlayer extends CustomEmbedPlayer + constructor: (data) -> + if not (this instanceof RTMPPlayer) + return new RTMPPlayer(data) + + @volume = VOLUME + @load(data) + + load: (data) -> + data.meta.embed = + tag: 'object' + src: 'https://fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf' + params: + flashvars: "src=#{data.id}&\ + streamType=live&\ + javascriptCallbackFunction=rtmpEventHandler&\ + autoPlay=true&\ + volume=#{VOLUME}" + super(data) + + getVolume: (cb) -> + cb(@volume) diff --git a/player/update.coffee b/player/update.coffee index 77686b8b..c66ae77b 100644 --- a/player/update.coffee +++ b/player/update.coffee @@ -8,6 +8,7 @@ TYPE_MAP = li: LivestreamPlayer tw: TwitchPlayer cu: CustomEmbedPlayer + rt: RTMPPlayer window.loadMediaPlayer = (data) -> if data.type of TYPE_MAP diff --git a/www/js/player-new.js b/www/js/player-new.js index bacf2793..8c37e44c 100644 --- a/www/js/player-new.js +++ b/www/js/player-new.js @@ -1,5 +1,5 @@ (function() { - var CustomEmbedPlayer, DailymotionPlayer, LivestreamPlayer, Player, SoundCloudPlayer, TYPE_MAP, TwitchPlayer, VideoJSPlayer, VimeoPlayer, YouTubePlayer, genParam, sortSources, + var CustomEmbedPlayer, DailymotionPlayer, LivestreamPlayer, Player, RTMPPlayer, SoundCloudPlayer, TYPE_MAP, TwitchPlayer, VideoJSPlayer, VimeoPlayer, YouTubePlayer, genParam, sortSources, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; @@ -847,6 +847,42 @@ })(Player); + window.rtmpEventHandler = function(id, event, data) { + if (event === 'volumechange') { + return PLAYER.volume = data.muted ? 0 : data.volume; + } + }; + + window.RTMPPlayer = RTMPPlayer = (function(superClass) { + extend(RTMPPlayer, superClass); + + function RTMPPlayer(data) { + if (!(this instanceof RTMPPlayer)) { + return new RTMPPlayer(data); + } + this.volume = VOLUME; + this.load(data); + } + + RTMPPlayer.prototype.load = function(data) { + data.meta.embed = { + tag: 'object', + src: 'https://fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf', + params: { + flashvars: "src=" + data.id + "&streamType=live&javascriptCallbackFunction=rtmpEventHandler&autoPlay=true&volume=" + VOLUME + } + }; + return RTMPPlayer.__super__.load.call(this, data); + }; + + RTMPPlayer.prototype.getVolume = function(cb) { + return cb(this.volume); + }; + + return RTMPPlayer; + + })(CustomEmbedPlayer); + TYPE_MAP = { yt: YouTubePlayer, vi: VimeoPlayer, @@ -856,7 +892,8 @@ sc: SoundCloudPlayer, li: LivestreamPlayer, tw: TwitchPlayer, - cu: CustomEmbedPlayer + cu: CustomEmbedPlayer, + rt: RTMPPlayer }; window.loadMediaPlayer = function(data) {