Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package seph.media.sephPlayer.models
- {
- import _-6.*;
- import com.wowza.encryptionAS3.*;
- import flash.events.*;
- import flash.media.*;
- import flash.net.*;
- import flash.utils.*;
- import seph.events.*;
- import seph.media.sephPlayer.*;
- import seph.media.sephPlayer.events.*;
- import seph.media.sephPlayer.utils.*;
- import seph.utils.*;
- public class VideoPlayModel extends seph.media.sephPlayer.models.AbstractPlayModel implements seph.media.sephPlayer.models.IPlayModel
- {
- public function VideoPlayModel(arg1:seph.media.sephPlayer.SephPlayer, arg2:seph.media.sephPlayer.utils.GUIManager)
- {
- super(arg1, arg2);
- var loc1:*;
- var loc2:*=((loc1 = seph.media.sephPlayer.models.VideoPlayModel).NUM_OF_MODEL + 1);
- loc1.NUM_OF_MODEL = loc2;
- arg2.notice("This is VideoPlayModel number " + seph.media.sephPlayer.models.VideoPlayModel.NUM_OF_MODEL + ". Make sure there is ONLY 1 of this for any time!");
- this.createVid(arg1);
- this._firstConnect = true;
- this.doConnect(arg1.config.streamer, arg1.config.streamerArg, arg1.config.cca);
- this._reConnectTimer = new flash.utils.Timer(6000, 1);
- this._reConnectTimer.addEventListener(flash.events.TimerEvent.TIMER_COMPLETE, this.doReconnect, false, 0, true);
- this._bufferEmptyTimer = new flash.utils.Timer(14000, 1);
- this._bufferEmptyTimer.addEventListener(flash.events.TimerEvent.TIMER_COMPLETE, this.doReconnect, false, 0, true);
- return;
- }
- public override function getLoadPerc():Number
- {
- if (this._ns)
- {
- return this._ns.bytesLoaded / this._ns.bytesTotal * 100;
- }
- return 0;
- }
- public override function set mute(arg1:Boolean):void
- {
- this._mute = arg1;
- _player.config.mute = this.mute;
- if (!this._ns)
- {
- return;
- }
- if (this._mute)
- {
- this._ns.soundTransform = new flash.media.SoundTransform(0);
- }
- else
- {
- this._ns.soundTransform = new flash.media.SoundTransform(1);
- }
- return;
- }
- public override function getStreamInfo():Object
- {
- if (this._ns)
- {
- return this._ns.info;
- }
- return null;
- }
- public override function dispose():Boolean
- {
- var loc1:*;
- if (this._ns)
- {
- this._ns.removeEventListener(flash.events.NetStatusEvent.NET_STATUS, this.onNetStatusHandler);
- this._ns.pause();
- this._ns.close();
- if (this._ns.client && this._ns.client is seph.media.sephPlayer.utils.NetStatusClient)
- {
- this._ns.client.dispose();
- }
- this._ns.client = {};
- this._ns = null;
- }
- this.disposeVid();
- if (this._nc)
- {
- try
- {
- this._nc.close();
- }
- catch (e:Error)
- {
- seph.utils.Traceable.doTrace(this + ": Error while trying to close NetConnection.", "error");
- }
- this._nc.removeEventListener(flash.events.NetStatusEvent.NET_STATUS, this.onNetStatusHandler);
- if (this._nc.client)
- {
- this._nc.client = {};
- }
- this._nc = null;
- }
- if (this._bwcheckTimer)
- {
- this._bwcheckTimer.stop();
- this._bwcheckTimer.removeEventListener(flash.events.TimerEvent.TIMER, this.onBWCheckTimerHandler);
- this._bwcheckTimer = null;
- }
- if (this._reConnectTimer)
- {
- this._reConnectTimer.stop();
- this._reConnectTimer.removeEventListener(flash.events.TimerEvent.TIMER_COMPLETE, this.doReconnect);
- this._reConnectTimer = null;
- }
- if (this._bufferEmptyTimer)
- {
- this._bufferEmptyTimer.stop();
- this._bufferEmptyTimer.removeEventListener(flash.events.TimerEvent.TIMER_COMPLETE, this.doReconnect);
- this._bufferEmptyTimer = null;
- }
- return super.dispose();
- }
- protected function disposeVid():void
- {
- if (this._vid)
- {
- this._vid.clear();
- if (this._vid.parent)
- {
- this._vid.parent.removeChild(this._vid);
- }
- this._vid = null;
- }
- return;
- }
- public function onBwCheck(arg1:*):void
- {
- return;
- }
- public override function pause():void
- {
- super.pause();
- if (this._ns)
- {
- this._pausePosition = this.time;
- this._ns.pause();
- }
- return;
- }
- public function onBWCheck(arg1:*):void
- {
- return;
- }
- public function close():void
- {
- seph.utils.Traceable.doTrace(this + ": NetConnection closed by server.");
- return;
- }
- protected function onBWCheckTimerHandler(arg1:flash.events.TimerEvent):void
- {
- if (!this._isPausing)
- {
- this.doCheckBW();
- }
- return;
- }
- public function get isPlayFinalCompleteDispatched():Boolean
- {
- return this._isPlayFinalCompleteDispatched;
- }
- protected function doCheckBW():void
- {
- var loc1:*;
- try
- {
- this._nc.call("checkBandwidth", null);
- }
- catch (e:Error)
- {
- seph.utils.Traceable.doTrace(this + ": Error calling \"checkBandwidth\" on server.", "error");
- }
- return;
- }
- public function get isPlayTransitioning():Boolean
- {
- return this._isPlayTransitioning;
- }
- public override function getApplicationConnectionCount(arg1:flash.events.Event=null):void
- {
- if (this._nc)
- {
- this._nc.call("getApplicationConnectionCount", this._appConnCountResponder);
- }
- return;
- }
- protected override function onAppConnCountResHandler(arg1:Number):void
- {
- _player.evtMngr.dispatchEvent(new seph.events.ItemEvent(seph.media.sephPlayer.events.SephPlayerEvent.CONNECTED_USERS_COUNT_RESULT, arg1));
- return;
- }
- public function get isRTMP():Boolean
- {
- return this._isRTMP;
- }
- {
- NUM_OF_MODEL = 0;
- }
- public override function get display():*
- {
- return this._vid;
- }
- protected function createVid(arg1:seph.media.sephPlayer.SephPlayer):void
- {
- this._vid = new flash.media.Video(4, 3);
- this._vid.smoothing = arg1.config.smoothing;
- if (arg1.numChildren == 0)
- {
- arg1.addChild(this._vid);
- }
- else
- {
- arg1.addChildAt(this._vid, 1);
- }
- this._vid.visible = false;
- this._vid.x = arg1.width / 2 - this._vid.width / 2;
- this._vid.y = arg1.height / 2 - this._vid.height / 2;
- return;
- }
- public function exploreVideoDecodingCapability():void
- {
- var loc1:*=_player.root.loaderInfo.parameters["wmode"];
- }
- protected function handleHardwareAccelerationCapability(arg1:*):void
- {
- var loc1:*=String(arg1);
- }
- public override function get time():Number
- {
- this._time = this._ns ? this._ns.time : 0;
- return this._time;
- }
- public override function doConnect(arg1:String=null, arg2:String=null, arg3:String=null):void
- {
- seph.utils.Traceable.doTrace(this + ": VideoPlayModel is making a connection...", "info");
- _guiMngr.notice(seph.media.sephPlayer.SephPlayer.LANG.CONNECTING, true);
- if (!this._nc)
- {
- this._nc = new flash.net.NetConnection();
- this._nc.addEventListener(flash.events.NetStatusEvent.NET_STATUS, this.onNetStatusHandler, false, 0, true);
- this._nc.client = this;
- }
- this._nc.connect(arg1, arg2, arg3);
- return;
- }
- protected function doReconnect(arg1:flash.events.TimerEvent=null):void
- {
- if (this._nc)
- {
- this._nc.removeEventListener(flash.events.NetStatusEvent.NET_STATUS, this.onNetStatusHandler);
- this._nc.client = {};
- }
- this._nc = new flash.net.NetConnection();
- this._nc.addEventListener(flash.events.NetStatusEvent.NET_STATUS, this.onNetStatusHandler, false, 0, true);
- this._nc.client = this;
- this._nc.connect(_player.config.streamer, _player.config.streamerArg);
- return;
- }
- private function streamingStatusHandler(arg1:flash.events.NetStatusEvent):void
- {
- var loc4:*=null;
- var loc5:*=null;
- var loc6:*=null;
- var loc1:*=String(arg1.info.code);
- var loc2:*=arg1.info.details;
- var loc3:*=arg1.info.description;
- _guiMngr.streamingStatusHandler(arg1);
- var loc7:*=loc1;
- switch (loc7)
- {
- case "NetConnection.Connect.Success":
- {
- if (this._firstConnect)
- {
- this._firstConnect = false;
- this.play();
- }
- else if (this._ns && seph.media.sephPlayer.utils.SephPlayerUtils.isFlash10Point1() && seph.media.sephPlayer.SephPlayerGlobal.SERVER_TYPE == "fms")
- {
- (loc7 = this._ns)["attach"](this._nc);
- (loc4 = new flash.net.NetStreamPlayOptions()).transition = flash.net.NetStreamPlayTransitions["RESUME"];
- loc4.streamName = _player.config.file;
- loc4.start = 0;
- loc4.len = -1;
- this._ns.play2(loc4);
- }
- else
- {
- (loc5 = _player.playlistMngr.getCurrentClip()).start = this._pausePosition;
- _player.playFile(loc5);
- }
- break;
- }
- case "NetConnection.Connect.Closed":
- {
- this._pausePosition = this.time;
- if (this._isRTMP && this._ns && !this._isPlayFinalCompleteDispatched)
- {
- this._reConnectTimer.start();
- }
- break;
- }
- case "NetConnection.Connect.Rejected":
- {
- loc6 = String(loc3);
- loc7 = seph.media.sephPlayer.SephPlayerGlobal.SERVER_TYPE;
- switch (loc7)
- {
- case "wowza":
- {
- loc6 = arg1.info.application;
- break;
- }
- }
- this._player.evtMngr.dispatchEvent(new seph.events.ItemEvent(seph.media.sephPlayer.events.SephPlayerEvent.NETCONNECTION_CONNECT_REJECTED, loc6));
- break;
- }
- case "NetConnection.Connect.Failed":
- {
- this._player.evtMngr.dispatchEvent(new flash.events.Event(seph.media.sephPlayer.events.SephPlayerEvent.NETCONNECTION_CONNECT_FAILED));
- if (this._isRTMP)
- {
- this._reConnectTimer.start();
- }
- break;
- }
- case "NetStream.Play.Complete":
- {
- this.onPlayFinalComplete();
- break;
- }
- case "NetStream.Play.Start":
- {
- this.onPlayStart();
- break;
- }
- case "NetStream.Play.StreamNotFound":
- {
- this._player.evtMngr.dispatchEvent(new flash.events.Event(seph.media.sephPlayer.events.SephPlayerEvent.STREAM_NOT_FOUND));
- break;
- }
- case "NetStream.Play.Transition":
- {
- this._isPlayTransitioning = true;
- break;
- }
- case "NetStream.Play.TransitionComplete":
- {
- this._isPlayTransitioning = false;
- break;
- }
- case "NetStream.Play.InsufficientBW":
- {
- break;
- }
- case "NetStream.Seek.Notify":
- {
- if (this._isPlaying)
- {
- if (arg1.info.description && String(arg1.info.description).indexOf("client-inBufferSeek") >= 0)
- {
- _guiMngr.notice("smart seek");
- }
- else
- {
- _guiMngr.notice("standard seek");
- }
- }
- else
- {
- this.onPlayStart();
- _guiMngr.streamingStatusHandler("NetStream.Play.Start");
- if (_timer && !_timer.running)
- {
- _timer.start();
- }
- }
- break;
- }
- case "NetStream.Seek.InvalidTime":
- {
- if (loc2 && !isNaN(Number(loc2)) && this._ns)
- {
- this._ns.seek(Number(loc2));
- }
- break;
- }
- case "NetStream.Pause.Notify":
- {
- break;
- }
- case "NetStream.Play.Stop":
- {
- seph.utils.Traceable.doTrace(this + ": Play.Stop dispatched.", "info");
- this._isNetStreamPlayStopDispatched = true;
- if (!this._isRTMP)
- {
- this.onPlayFinalComplete();
- }
- break;
- }
- case "NetStream.Buffer.Full":
- {
- if (!this._isNetStreamPlayStartDispatched)
- {
- seph.utils.Traceable.doTrace("NetStream.Play.Start wasn\'t dispatched. This message should appear once per item played.\nPlayer config: " + _player.getConfig(), "info");
- this.onPlayStart();
- }
- this._bufferEmptyTimer.stop();
- this._bufferEmptyTimer.reset();
- break;
- }
- case "NetStream.Buffer.Empty":
- {
- if (this._ns)
- {
- if (this._isNetStreamPlayStopDispatched || !isNaN(this.time) && this.time > 0 && this.time >= _player.metadata.duration - 0.3)
- {
- this.onPlayFinalComplete();
- }
- }
- this._pausePosition = this.time;
- if (this.isRTMP && !this._bufferEmptyTimer.running && this._isPlaying)
- {
- this._bufferEmptyTimer.start();
- }
- break;
- }
- }
- return;
- }
- public function onNetStatusHandler(arg1:flash.events.NetStatusEvent):void
- {
- seph.utils.Traceable.doTrace("NetStatus dispatched from " + arg1.currentTarget + ": ", "info");
- seph.utils.Traceable.doTrace("\t" + arg1.info.code, "info");
- if (seph.media.sephPlayer.SephPlayerGlobal.SERVER_TYPE == "wowza")
- {
- if (arg1.info.secureToken != null)
- {
- this._nc.call(_-6._-3._-0(-688, 458), null, com.wowza.encryptionAS3.TEA.decrypt(arg1.info.secureToken, _-6._-3._-0(-689, 457)));
- }
- }
- this.streamingStatusHandler(arg1);
- return;
- }
- public override function play(arg1:String=null, arg2:Number=0):void
- {
- _player.stage.dispatchEvent(new flash.events.Event(flash.events.Event.RESIZE));
- if (this._ns)
- {
- this._ns.removeEventListener(flash.events.NetStatusEvent.NET_STATUS, this.onNetStatusHandler);
- if (this._ns.client && this._ns.client is seph.media.sephPlayer.utils.NetStatusClient)
- {
- this._ns.client.dispose();
- }
- this._ns.client = {};
- this._ns.pause();
- this._ns.close();
- this._vid.clear();
- this._vid.attachCamera(null);
- this._ns = null;
- }
- if (!this._nc || !this._nc.connected)
- {
- seph.utils.Traceable.doTrace(this + ": NetConnection isn\'t connected yet!", "error");
- }
- else
- {
- this._ns = new flash.net.NetStream(this._nc);
- this._ns.addEventListener(flash.events.NetStatusEvent.NET_STATUS, this.onNetStatusHandler, false, 0, true);
- this._ns.bufferTime = _player.config.live ? 0.25 : 3;
- this._ns.client = new seph.media.sephPlayer.utils.NetStatusClient(_player);
- this._vid.attachNetStream(this._ns);
- this.mute = _player.config.mute;
- this._ns.play(arg1 ? arg1 : _player.config.file);
- if (_player.config.streamer)
- {
- this._isRTMP = true;
- this._ns.bufferTime = 5;
- }
- else
- {
- this._isRTMP = false;
- }
- }
- return;
- }
- public override function switchToStreamName(arg1:String):void
- {
- if (!this._ns || !arg1)
- {
- seph.utils.Traceable.doTrace(this + ": Unable to switchToStreamName. There\'s either no NetStream or any bitrate name specified.");
- return;
- }
- var loc1:*=new flash.net.NetStreamPlayOptions();
- loc1.oldStreamName = this._player.config.file;
- loc1.streamName = arg1;
- loc1.transition = flash.net.NetStreamPlayTransitions.SWITCH;
- this._ns.play2(loc1);
- this._player.config.file = arg1;
- return;
- }
- public function setTitle():String
- {
- return "media";
- }
- public override function togglePause():void
- {
- super.togglePause();
- if (this._ns)
- {
- this._pausePosition = this.time;
- this._ns.togglePause();
- }
- return;
- }
- public override function resume():void
- {
- super.resume();
- if (this._ns)
- {
- this._ns.resume();
- }
- return;
- }
- public override function stop():void
- {
- if (this._isPlaying)
- {
- this.pause();
- }
- return;
- }
- public override function seek(arg1:Number):void
- {
- if (!isNaN(arg1) && !(arg1 == 0) && this._ns)
- {
- this._ns.seek(arg1);
- }
- return;
- }
- protected override function onPlayStart():void
- {
- if (!_isPlaying)
- {
- this._isPlaying = true;
- if (this._ns.time <= 0.5)
- {
- if (this._vid)
- {
- this._vid.visible = true;
- }
- if (_timer)
- {
- _timer.reset();
- }
- else
- {
- _timer = new flash.utils.Timer(50);
- _timer.addEventListener(flash.events.TimerEvent.TIMER, this.onTimerHandler, false, 0, true);
- }
- _timer.start();
- this.onPlayFirstStart();
- this._isPlayFinalCompleteDispatched = false;
- }
- super.onPlayStart();
- this._isNetStreamPlayStopDispatched = false;
- this._isNetStreamPlayStartDispatched = true;
- }
- return;
- }
- protected override function onPlayFirstStart():void
- {
- if (_player.config.live)
- {
- this.getApplicationConnectionCount();
- if (this._appConnCountTimer)
- {
- this._appConnCountTimer.reset();
- this._appConnCountTimer.start();
- }
- else
- {
- this._appConnCountTimer = new flash.utils.Timer(30000);
- this._appConnCountTimer.addEventListener(flash.events.TimerEvent.TIMER, this.getApplicationConnectionCount, false, 0, true);
- this._appConnCountTimer.start();
- }
- }
- if (_player.config.start > 0)
- {
- this._guiMngr.updateRightTF(seph.media.sephPlayer.utils.SephPlayerUtils.convertFromSecToMin(_player.metadata.duration));
- this._player.stage.dispatchEvent(new flash.events.Event(flash.events.Event.RESIZE));
- this.seek(_player.config.start);
- }
- super.onPlayFirstStart();
- return;
- }
- protected override function onPlayFinalComplete():void
- {
- if (this._isPlayFinalCompleteDispatched)
- {
- return;
- }
- this._isPlayFinalCompleteDispatched = true;
- if (_isPlaying)
- {
- _isPlaying = false;
- this._isNetStreamPlayStopDispatched = true;
- this._isNetStreamPlayStartDispatched = false;
- if (_timer)
- {
- _timer.stop();
- }
- if (this._vid)
- {
- this._vid.clear();
- this._vid.attachNetStream(null);
- }
- if (!this._firstConnect && !_player.isInInStreamSession)
- {
- _player.playlistMngr.getCurrentClip().start = 0;
- _player.config.start = 0;
- }
- _player.guiMngr.notice(seph.media.sephPlayer.SephPlayer.LANG.PLAYBACK_END);
- super.onPlayFinalComplete();
- }
- return;
- }
- protected override function onPlayComplete():void
- {
- seph.utils.Traceable.doTrace(this + ": Play.Complete dispatched", "info");
- this._isNetStreamPlayStopDispatched = true;
- this._isNetStreamPlayStartDispatched = false;
- super.onPlayComplete();
- return;
- }
- public override function onPlayStatus(arg1:*):void
- {
- if (arg1["id"] && arg1["id"]["code"])
- {
- _guiMngr.streamingStatusHandler(String(arg1["id"]["code"]));
- var loc1:*=String(arg1["id"]["code"]);
- switch (loc1)
- {
- case "NetStream.Play.Complete":
- {
- this.onPlayFinalComplete();
- break;
- }
- }
- }
- return;
- }
- public override function onMetadataReceived(arg1:flash.events.Event):void
- {
- _guiMngr.updateRightTF(seph.media.sephPlayer.utils.SephPlayerUtils.convertFromSecToMin(_player.metadata.duration));
- super.onMetadataReceived(arg1);
- this.exploreVideoDecodingCapability();
- seph.utils.Traceable.doTrace(this + ": Metadata received.", "info");
- return;
- }
- public function onBWDone(arg1:Number=NaN, arg2:Number=NaN, arg3:Number=NaN, arg4:Number=NaN):void
- {
- var loc1:*=0;
- seph.utils.Traceable.doTrace("onBWDone: kbitDown:" + arg1 + " deltaDown:" + arg2 + " deltaTime:" + arg3 + " latency:" + arg4);
- if (!isNaN(arg1))
- {
- _player.usrDetailsMngr.bandwidth = arg1;
- if (!this._isPlayTransitioning && this._player.playlistMngr.getCurrentClip().streams && this._player.playlistMngr.getCurrentClip().streams.length > 1)
- {
- if (arg1 < seph.media.sephPlayer.SephPlayerGlobal.BITRATE_THRESHOLD_SIMPLE)
- {
- _player.guiMngr.receiveGUIEvent(seph.media.sephPlayer.events.SephPlayerEvent.BITRATE_GUI_CHANGE_REQUEST, 1);
- }
- else
- {
- loc1 = this._player.playlistMngr.getCurrentClip().streams.length;
- _player.guiMngr.receiveGUIEvent(seph.media.sephPlayer.events.SephPlayerEvent.BITRATE_GUI_CHANGE_REQUEST, loc1);
- }
- }
- }
- this._player.evtMngr.dispatchEvent(new seph.events.ItemEvent(seph.media.sephPlayer.events.SephPlayerEvent.BANDWIDTH_DETECTED, arg1));
- if (this._bwcheckTimer)
- {
- this._bwcheckTimer.reset();
- this._bwcheckTimer.start();
- }
- else if (this._player.config.allowBWCheck)
- {
- this._bwcheckTimer = new flash.utils.Timer(300000, 1);
- this._bwcheckTimer.addEventListener(flash.events.TimerEvent.TIMER_COMPLETE, this.onBWCheckTimerHandler, false, 0, true);
- this.doCheckBW();
- }
- return;
- }
- public override function onTimerHandler(arg1:flash.events.TimerEvent):void
- {
- var loc1:*=this.getProgPerc();
- var loc2:*=this.getLoadPerc();
- _guiMngr.updateBar(loc1, loc2);
- _guiMngr.updateLeftTF(seph.media.sephPlayer.utils.SephPlayerUtils.convertFromSecToMin(this.time));
- this._player.evtMngr.onPlayTimeUpdatedHandler(new seph.events.ItemEvent(seph.media.sephPlayer.events.SephPlayerEvent.PLAY_TIME_UPDATED, this.time));
- return;
- }
- public override function getProgPerc():Number
- {
- if (this._ns)
- {
- return isNaN(_player.metadata.duration) ? 0 : this.time / Number(_player.metadata.duration) * 100;
- }
- return 0;
- }
- protected var _firstConnect:Boolean=true;
- protected var _reConnectTimer:flash.utils.Timer;
- protected var _bufferEmptyTimer:flash.utils.Timer;
- protected var stageVideoUsed:Boolean=false;
- protected var _nc:flash.net.NetConnection;
- protected var _ns:flash.net.NetStream;
- protected var _isNetStreamPlayStopDispatched:Boolean=false;
- protected var _isNetStreamPlayStartDispatched:Boolean=false;
- protected var _isPlayFinalCompleteDispatched:Boolean=false;
- protected var _isPlayTransitioning:Boolean=false;
- protected var _bwcheckTimer:flash.utils.Timer;
- protected var _isRTMP:Boolean=false;
- protected var _playCompleteTimer:flash.utils.Timer;
- public static var NUM_OF_MODEL:Number=0;
- protected var _vid:flash.media.Video;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement