home *** CD-ROM | disk | FTP | other *** search
- class mx.controls.streamingmedia.FLVPlayer extends mx.controls.streamingmedia.AbstractPlayer
- {
- var _mediaUrl;
- var _videoHolder;
- var _video;
- var _totalTime;
- var _listeners;
- var _isLoaded;
- var _sound;
- var _ns;
- var _nc;
- var _videoHeight;
- var _videoWidth;
- var _momentaryPlayId;
- function FLVPlayer(aMediaUrl, aVideoHolder, aTotalTime)
- {
- super();
- if(aMediaUrl == null || aVideoHolder == null || aTotalTime == null)
- {
- }
- this._mediaUrl = aMediaUrl;
- this._videoHolder = aVideoHolder;
- this._video = this._videoHolder._video;
- this._totalTime = aTotalTime;
- this.init();
- }
- function init()
- {
- this._listeners = new Array();
- this.setPlaying(false);
- this._isLoaded = 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 "FLVPlayer: Playing " + this.getMediaUrl();
- }
- function close()
- {
- this._ns.close();
- this._nc.close();
- this._video.clear();
- }
- function load()
- {
- this._nc = new NetConnection();
- this._nc.connect(null);
- this._ns = new mx.controls.streamingmedia.PlayerNetStream(this._nc,this);
- this.assignBufferTime();
- this._video.attachVideo(this._ns);
- this._videoHeight = this._video.height;
- this._videoWidth = this._video.width;
- this._videoHolder.attachAudio(this._ns);
- this._ns.play(this._mediaUrl);
- this._isLoaded = true;
- this._videoHolder._visible = false;
- this.setPlaying(false);
- }
- function assignBufferTime()
- {
- var _loc2_ = this._totalTime / 4;
- if(_loc2_ < 0.1)
- {
- _loc2_ = 0.1;
- }
- else if(_loc2_ > 5)
- {
- _loc2_ = 5;
- }
- this._ns.setBufferTime(_loc2_);
- }
- function play(startingPoint)
- {
- if(!this._isLoaded)
- {
- this.load();
- }
- if(startingPoint != null)
- {
- this._ns.seek(startingPoint);
- }
- this._ns.pause(false);
- this.setPlaying(true);
- }
- function pause()
- {
- this._ns.pause(true);
- this.setPlaying(false);
- }
- function stop()
- {
- this.pause();
- this.setPlayheadTime(0);
- }
- function getPlayheadTime()
- {
- return this._ns.time;
- }
- function setPlayheadTime(position)
- {
- this._ns.seek(position);
- if(!mx.controls.streamingmedia.StreamingMediaConstants.SCRUBBING)
- {
- if(!this.isPlaying())
- {
- this._ns.pause(false);
- this._momentaryPlayId = setInterval(this,"doneUpdateFrame",50);
- }
- }
- }
- function doneUpdateFrame()
- {
- clearInterval(this._momentaryPlayId);
- this._momentaryPlayId = null;
- this._ns.pause(true);
- }
- function playStopped()
- {
- this.pause();
- this.broadcastEvent("complete");
- }
- function getMediaUrl()
- {
- return this._mediaUrl;
- }
- function setMediaUrl(aUrl)
- {
- this._mediaUrl = aUrl;
- this._isLoaded = false;
- if(this.isPlaying())
- {
- 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;
- this.assignBufferTime();
- }
- 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)
- {
- }
- }
-