var EnumFPlayerType={PREVIEW_PLAYER:0,PLAYBACK_PLAYER:1},BufferTimeConfig={FLUENT_BUFFER:1.6,BALANCE_BUFFER:.8,CLEAR_BUFFER:.6};function FPlayer(e,t){var n,r,i=e,s=t,a=!1,o=["ready"],u={play:"onPlay",error:"onError",pause:"onPause",idle:"onIdle",buffer:"onBuffer",ready:"onReady",walking:"onTime"};function l(e){return"fplayer"+s+"-"+e}function h(e){return l(e)+"_wrapper"}this.getStream=function(){return FPlayer.getCurrentStreamType()},EventListener.apply(this),this._on=this.on,this.on=function(e,t){var n;return u[e]&&o.indexOf(e)<0&&(n=this,o.push(e),r[u[e]]((function(t){n.trigger(e,t)}))),this._on(e,t)},n=$("#"+h(i)),this.isReady=function(){return null!==r},this.getMode=this.getType=function(){return s},this.getChannel=function(){return i},this.isPlaying=function(){if(!r)return!1;var e=r.getState();return console.dbg(e),r.getState&&"PLAYING"==r.getState()},this.isIdle=function(){return r.getState&&"IDLE"==r.getState()},this.setVolume=function(e){return r.setVolume(e)},this.isBuffering=function(){return"BUFFERING"==r.getState()},this.isPaused=function(){return"PAUSED"==r.getState()},this.load=function(e){return r.load([{file:e}]),this},this.destroy=function(){this.stop(),$("#"+h(i)).remove(),$("#"+l(i)).remove()},this.play=function(){return this.isReady()?(this.isPlaying()||(this.getType()==EnumCurState.PREVIEW&&FPlayer.setCurrentStreamType(null==FPlayer.tempStream?this.getStream():FPlayer.tempStream),r.play(),this._setVol()),this):this},this._setVol=function(){FPlayer.getMode()==EnumCurState.PLAYBACK?r.setVolume(PlayerPlayback.getVolume()):r.setVolume(PlayerPreview.getVolume())},this.pause=function(){return this.isReady()?(this.isPlaying()&&r.pause(),this):this},this.stop=function(){return this.isReady()?(r&&r.stop(),this.getType()==EnumCurState.PREVIEW&&(FPlayer.tempStream=this.getStream()),this):this},this.hide=function(){var e=$("#"+l(i));return e.css({width:"0px"}),e.css({height:"0px"}),this.trigger("hide")},this.show=function(){$("#"+l(i));return this.trigger("show")},this.seek=function(e){r.seek(e)},this.playUrl=function(e){r.playUrl(e)},this.setPosition=function(){var e;return 0==n.length?this:(e=ViewManager.getViewObject(ChannelManager.get(i).getViewId(),EnumCurState.PREVIEW).getClientArea(),$("#channelitem"+i),r?(r.setSize(e.width,e.height,e.left,0),$("#"+l(i)).css({height:e.height,width:e.width,left:e.left,top:e.top}),this):this)},this.playStream=function(e,t){console.dbg("Flash.playStream: ",t),this.getStream()!=e?(FPlayer.setCurrentStreamType(e),this.playUrl(t),this.setPosition()):this.play()},this.isExactFit=function(){return r&&r.stretching()},this.setExactFit=function(e){r.setExactFit(e),e?this.params&&(this.params.stretching="exactfit"):this.params&&(this.params.stretching="screen")},this.getPlaylist=function(){return r.getPlaylist()},this.getSafeRegion=function(){return r.getSafeRegion()},this.continuePlay=function(){return r.continuePlay()},this.setBufferTime=function(e){return r.setBufferTime(e)},this.updateEncode=function(){r.destroy(),r.continuePlay()},this.setup=function(e){var t,s=this;return 0==$("#"+h(i)).length&&0==$("#"+l(i)).length?($("#preview_plugin_container").append('
'),$("#"+l(i)).css({position:"relative","z-index":"99",height:"1200px"}),console.dbg("Flash Player: Opened Video URL ",e.url),(n=$("#"+l(i))).append('
'),(t=this).params||(t.params={file:e.url,flashplayer:"swf/BcFlashPlayer.swf",fallback:"false",stretching:"exactfit",autostart:!0,rtmp:{bufferlength:t.getType()==EnumCurState.PLAYBACK?1.5:.6},skin:"swf/five.xml?timeVersion="+(new Date).getTime(),modes:"flash"}),FPlayer.setCurrentStreamType(e.stream),t.getType()==EnumCurState.PLAYBACK&&(t.params.seekTo=e.seekTo,console.dbg("Flash Player: Seek To",e.seekTo)),BcFlashPlayer(l(i)).setup(t.params).onSetupError((function(e){console.dbg("BcFlashPlayer onSetupError: ",e.message)})).onReady((function(){a||(a=!0,r=getBcFlashPlayerByDomId(l(i)),s.setPosition(),FPlayer.trigger("ready",[t]),this.onVolume=function(e){console.dbg("Volume changed to",e.volume)},console.openFlashDebuger=function(e){e?r.openLogInfo(!0):r.openLogInfo(!1)},this.onPlay=function(e){"PLAYING"==e.newstate&&(t.getType()!=EnumCurState.PLAYBACK||t.isSeekd||(t.isSeekd=!0,t.params.seekTo>0&&r.seek(t.params.seekTo)),FPlayer.trigger("statechange",[t,EnumChannelStatus.PLAYING,EnumViewStatus.PLAYING]),console.dbg("Flash Player Event: onPlay -",e),s._setVol())},this.onError=function(e){console.dbg("Flash Player Event: onError -",e),FPlayer.trigger("statechange",[t,EnumChannelStatus.CLOSED,EnumViewStatus.ERROR])},s._setVol(),this.onBuffer=function(e){console.dbg("Flash Player Event: onBuffer -",e),"BUFFERING"==e.newstate&&FPlayer.trigger("statechange",[t,EnumChannelStatus.PLAYING,EnumViewStatus.BUFFERING])},this.onFullscreen=function(e){e.fullscreen?this.setControls(!1):this.setControls(!0)},this.onPause=function(e){console.dbg("Flash Player Event: onPause -",e),"PAUSED"==e.newstate&&FPlayer.trigger("statechange",[t,EnumChannelStatus.CLOSED,EnumViewStatus.PAUSED])},this.onIdle=function(e){console.dbg("Flash Player Event: onStop -",e),FPlayer.trigger("statechange",[t,EnumChannelStatus.CLOSED,EnumViewStatus.PAUSED])},this.onComplete=function(e){console.dbg("Flash Player Event: onComplete -",e),FPlayer.trigger("statechange",[t,EnumChannelStatus.CLOSED,EnumViewStatus.CLOSED]),FPlayer.trigger("complete",[t])},this.onTime=function(e){t.isSeekd&&(t.params.seekTo=e.position),FPlayer.trigger("walking",[t,e])})})),FPlayer.trigger("statechange",[s,EnumChannelStatus.PLAYING,EnumViewStatus.BUFFERING]),n=$("#"+h(i)).addClass("fplayer"),this):this}}EventListener.apply(FPlayer),function(){var e={PREVIEW:{},PLAYBACK:{}},t=EnumCurState.PREVIEW;FPlayer.setMode=function(e){switch(e){case EnumCurState.PREVIEW:case EnumCurState.PLAYBACK:break;default:return!1}return t=e,!0},FPlayer.getMode=function(){return t},FPlayer.open=function(n,r){return void 0===e[t][n]&&(e[t][n]=new FPlayer(n,t).setup(r)),e[t][n]},FPlayer.close=function(n){return void 0===e[t][n]||(this.trigger("statechange",[e[t][n],EnumChannelStatus.CLOSED,EnumViewStatus.CLOSED]),e[t][n].destroy(),delete e[t][n]),this},FPlayer.play=function(n){return void 0===e[t][n]||e[t][n].play(),this},FPlayer.continuePlay=function(n){if(void 0===e[t][n])throw{message:"No such a player.",name:"FlashPlayer"};return e[t][n].continuePlay(),this},FPlayer.pause=function(n){return void 0===e[t][n]||e[t][n].pause(),this},FPlayer.stop=function(n){return void 0===e[t][n]||e[t][n].stop(),this},FPlayer.show=function(n){return void 0===e[t][n]||e[t][n].show(),this},FPlayer.hide=function(n){return void 0===e[t][n]||e[t][n].hide(),this},FPlayer.get=function(n){return e[t][n]},FPlayer.setCurrentStreamType=function(n){if(this._streamType=n,void 0===e[t][0])return this;var r=BufferTimeConfig.CLEAR_BUFFER;return n==EnumStreamType.FLUENT||n==EnumStreamType.CLIP?r=BufferTimeConfig.FLUENT_BUFFER:n==EnumStreamType.BALANCED&&(r=BufferTimeConfig.BALANCE_BUFFER),e[t][0].setBufferTime(r),this},FPlayer.getCurrentStreamType=function(){return this._streamType}}();