home *** CD-ROM | disk | FTP | other *** search
- class mx.controls.streamingmedia.RTMPPlayer extends mx.controls.streamingmedia.AbstractPlayer
- {
- var _mediaUrl;
- var _mediaType;
- var _videoHolder;
- var _video;
- var _totalTime;
- var _listeners;
- var _connectTimeOutId;
- var _protocol;
- var _port;
- var _appUrl;
- var _streamName;
- var _isLoaded;
- var _isLoading;
- var _isPlayPending;
- var _nc_rtmp;
- var _nc_rtmpt;
- var _playHeadPos;
- var _isPausing;
- var _sound;
- var _ns;
- var _videoHeight;
- var _videoWidth;
- var _player;
- var popConnection;
- var _conn_Id;
- var _isSeeking;
- var _momentaryPlayId;
- var _statusCount;
- var _checkCompleteId;
- function RTMPPlayer(aMediaUrl, aMediaType, aVideoHolder, aTotalTime)
- {
- super();
- if(aMediaUrl == null || aVideoHolder == null || aTotalTime == null)
- {
- }
- this._mediaUrl = aMediaUrl;
- this._mediaType = aMediaType;
- this._videoHolder = aVideoHolder;
- this._video = this._videoHolder._video;
- this._totalTime = aTotalTime;
- this._listeners = new Array();
- this._connectTimeOutId = null;
- this.init();
- }
- function init()
- {
- var _loc2_ = undefined;
- _loc2_ = this._mediaUrl.indexOf(":");
- if(_loc2_ == -1)
- {
- }
- this._protocol = this._mediaUrl.substring(0,_loc2_).toLowerCase();
- if(this._protocol != "rtmp" && this._protocol != "rtmps" && this._protocol != "rtmpt")
- {
- }
- var _loc3_ = this._mediaUrl.substring(_loc2_ + 1,this._mediaUrl.length);
- this._port = null;
- var _loc5_ = _loc3_.indexOf(":");
- if(_loc5_ != -1)
- {
- this._port = _loc3_.substring(_loc5_ + 1,_loc3_.length);
- var _loc4_ = this._port.indexOf("/");
- if(_loc4_ != -1 && _loc4_ < _loc5_)
- {
- this._port = this._port.substring(0,_loc4_);
- }
- else
- {
- this._port = null;
- }
- }
- _loc2_ = _loc3_.lastIndexOf("/");
- if(_loc2_ == -1)
- {
- }
- this._appUrl = _loc3_.substring(0,_loc2_);
- this._streamName = _loc3_.substring(_loc2_ + 1,_loc3_.length);
- if(this._streamName.length == 0)
- {
- }
- if(this._mediaType == mx.controls.streamingmedia.StreamingMediaConstants.FLV_MEDIA_TYPE)
- {
- _loc2_ = this._streamName.indexOf(".");
- if(_loc2_ != -1)
- {
- var _loc6_ = undefined;
- _loc6_ = this._streamName.substring(_loc2_).toLowerCase();
- if(_loc6_ == ".flv")
- {
- this._streamName = this._streamName.substring(0,_loc2_);
- }
- }
- this._streamName = "flv:" + this._streamName;
- }
- else if(this._mediaType == mx.controls.streamingmedia.StreamingMediaConstants.MP3_MEDIA_TYPE)
- {
- _loc2_ = this._streamName.indexOf(".");
- if(_loc2_ != -1)
- {
- _loc6_ = this._streamName.substring(_loc2_).toLowerCase();
- if(_loc6_ == ".mp3")
- {
- this._streamName = this._streamName.substring(0,_loc2_);
- }
- }
- this._streamName = "mp3:" + this._streamName;
- }
- this.setPlaying(false);
- this._isLoaded = false;
- this._isLoading = false;
- this._isPlayPending = false;
- this._nc_rtmp = null;
- this._nc_rtmpt = null;
- this._playHeadPos = 0;
- this.setSeeking(false);
- this._isPausing = false;
- this._sound = new Sound(this._videoHolder);
- this.setVolume(mx.controls.streamingmedia.StreamingMediaConstants.DEFAULT_VOLUME);
- }
- function addListener(aListener)
- {
- this._listeners.push(aListener);
- }
- function removeAllListeners()
- {
- this._listeners.length = 0;
- }
- function broadcastEvent(status)
- {
- var _loc2_ = 0;
- while(_loc2_ < this._listeners.length)
- {
- this._listeners[_loc2_].handlePlayer(this,status);
- _loc2_ = _loc2_ + 1;
- }
- }
- function bufferIsFull()
- {
- this.broadcastEvent("start");
- if(!this.isPlaying())
- {
- this.pause();
- }
- }
- function resizeVideo()
- {
- this.broadcastEvent("resizeVideo");
- if(!this.isPlaying())
- {
- this.pause();
- }
- }
- function toString()
- {
- return "RTMPPlayer: Playing " + this.getMediaUrl();
- }
- function close()
- {
- this._ns.onStatus = null;
- this._ns.close();
- this._ns = null;
- if(this._nc_rtmp != null)
- {
- this._nc_rtmp.onStatus = null;
- this._nc_rtmp.close();
- this._nc_rtmp = null;
- }
- if(this._nc_rtmpt != null)
- {
- this._nc_rtmpt.onStatus = null;
- this._nc_rtmpt.close();
- this._nc_rtmpt = null;
- }
- this._video.clear();
- }
- function load()
- {
- this._isLoading = true;
- this.actualConnect();
- if(this._connectTimeOutId != null)
- {
- clearInterval(this._connectTimeOutId);
- this._connectTimeOutId = null;
- }
- this._connectTimeOutId = setInterval(this,"onConnectTimeOut",60000);
- }
- function startStream(nc)
- {
- clearInterval(this._connectTimeOutId);
- this._connectTimeOutId = null;
- this._ns = new mx.controls.streamingmedia.PlayerNetStream(nc,this);
- if(this._mediaType == mx.controls.streamingmedia.StreamingMediaConstants.FLV_MEDIA_TYPE)
- {
- this._video.attachVideo(this._ns);
- }
- this._video.attachVideo(this._ns);
- this._videoHeight = this._video.height;
- this._videoWidth = this._video.width;
- this._ns.setBufferTime(5);
- this._videoHolder.attachAudio(this._ns);
- this._ns.play(this._streamName,0,-1);
- this._isLoading = false;
- this._isLoaded = true;
- this._videoHolder._visible = false;
- this.setPlaying(false);
- if(this._isPlayPending)
- {
- this.play(null);
- }
- else
- {
- this._isPausing = false;
- this.pause();
- }
- }
- function onConnectTimeOut()
- {
- clearInterval(this._connectTimeOutId);
- this._connectTimeOutId = null;
- if(this._nc_rtmpt != null)
- {
- this._nc_rtmpt.onStatus = null;
- this._nc_rtmpt.close();
- this._nc_rtmpt = null;
- }
- if(this._nc_rtmp != null)
- {
- this._nc_rtmp.onStatus = null;
- this._nc_rtmp.close();
- this._nc_rtmp = null;
- }
- this._isLoading = false;
- this._isLoaded = false;
- }
- function actualConnect()
- {
- if(this._protocol == "rtmp")
- {
- this._nc_rtmp = new mx.controls.streamingmedia.RTMPConnection(this);
- this._nc_rtmp.onStatus = function(info)
- {
- if(info.code == "NetConnection.Connect.Success")
- {
- clearInterval(this._player._conn_Id);
- this._nc_rtmpt.onStatus = null;
- this._nc_rtmpt.close();
- this._nc_rtmpt = null;
- this._player.startStream(this);
- this.popConnection();
- }
- };
- this._nc_rtmp.connect("rtmp:" + this._appUrl,this._streamName);
- }
- if(this._protocol == "rtmpt" || this._protocol == "rtmp" && this._port == null)
- {
- this._nc_rtmpt = new mx.controls.streamingmedia.RTMPConnection(this);
- this._nc_rtmpt.onStatus = function(info)
- {
- if(info.code == "NetConnection.Connect.Success")
- {
- this._nc_rtmp.onStatus = null;
- this._nc_rtmp.close();
- this._nc_rtmp = null;
- this._player.startStream(this);
- this.popConnection();
- }
- };
- if(this._protocol == "rtmpt")
- {
- this._nc_rtmpt.connect("rtmpt:" + this._appUrl,this._streamName);
- }
- else
- {
- clearInterval(this._conn_Id);
- this._conn_Id = setInterval(this,"connectRtmpt",3000);
- }
- }
- }
- function connectRtmpt()
- {
- clearInterval(this._conn_Id);
- this._nc_rtmpt.connect("rtmpt:" + this._appUrl,this._streamName);
- }
- function play(startingPoint)
- {
- this.setPlaying(true);
- if(startingPoint != null)
- {
- this._playHeadPos = startingPoint;
- }
- if(this._isLoading || !this._isLoaded)
- {
- this._isPlayPending = true;
- if(!this._isLoaded)
- {
- this.load();
- }
- return undefined;
- }
- this._isPlayPending = false;
- this._isPausing = false;
- this._ns.pause(false);
- this._ns.seek(this._playHeadPos);
- }
- function pause()
- {
- if(!this._isPausing)
- {
- this._ns.pause(true);
- this._isPausing = true;
- this._isPlayPending = false;
- this._playHeadPos = this._ns.time;
- this.setPlaying(false);
- }
- }
- function stop()
- {
- this.pause();
- this.setPlayheadTime(0);
- }
- function getPlayheadTime()
- {
- return this._ns.time;
- }
- function setPlayheadTime(position)
- {
- this._playHeadPos = position;
- if(!this._isSeeking)
- {
- this._ns.seek(position);
- this.setSeeking(true);
- }
- if(!mx.controls.streamingmedia.StreamingMediaConstants.SCRUBBING)
- {
- if(!this.isPlaying())
- {
- this._ns.pause(false);
- clearInterval(this._momentaryPlayId);
- this._momentaryPlayId = setInterval(this,"doneUpdateFrame",50);
- }
- }
- }
- function doneUpdateFrame()
- {
- clearInterval(this._momentaryPlayId);
- this._momentaryPlayId = null;
- this._ns.pause(true);
- }
- function playStopped()
- {
- this._statusCount = 2;
- clearInterval(this._checkCompleteId);
- this._checkCompleteId = setInterval(this,"checkComplete",50);
- }
- function checkComplete()
- {
- if(this._ns.bufferLength <= 0.001)
- {
- if(this._statusCount <= 0)
- {
- clearInterval(this._checkCompleteId);
- this._checkCompleteId = null;
- this.pause();
- this.broadcastEvent("complete");
- }
- else
- {
- this._statusCount -= 1;
- }
- }
- }
- function getMediaUrl()
- {
- return this._mediaUrl;
- }
- function setMediaUrl(aUrl)
- {
- this._mediaUrl = aUrl;
- this._isLoaded = false;
- var _loc3_ = this.isPlaying();
- var _loc2_ = this.getVolume();
- this.close();
- this.init();
- this.setVolume(_loc2_);
- if(_loc3_)
- {
- this.play(0);
- }
- else
- {
- this.load();
- }
- }
- function getVolume()
- {
- return this._sound.getVolume();
- }
- function setVolume(aVol)
- {
- this._sound.setVolume(aVol);
- }
- function getMediaBytesLoaded()
- {
- return this._ns.bytesLoaded;
- }
- function getMediaBytesTotal()
- {
- return this._ns.bytesTotal;
- }
- function getTotalTime()
- {
- return this._totalTime;
- }
- function setTotalTime(aTime)
- {
- this._totalTime = aTime;
- }
- function mediaLoaded()
- {
- }
- function logError(error)
- {
- }
- function isSizeSet()
- {
- if(this._video.width > 0 && this._video.height > 0)
- {
- return true;
- }
- return false;
- }
- function isSizeChange()
- {
- if(this._video.width != this._videoWidth || this._video.height != this._videoHeight)
- {
- this._videoWidth = this._video.width;
- this._videoHeight = this._video.height;
- return true;
- }
- return false;
- }
- function setSeeking(isSeeking)
- {
- this._isSeeking = isSeeking;
- }
- }
-