home *** CD-ROM | disk | FTP | other *** search
Wrap
class mx.controls.MediaDisplay extends mx.core.UIComponent { var _deadPreview; var _startingTime; var _playingBeforeDisabled; var _started; var _sendCompleteEvent; var _fullyLoaded; var _screenAccommodator; var _cuePoints; var initCuePointNames; var initCuePointTimes; var _mostRecentCuePoint; var _playerImpl; var _contentPath; var _videoHolder; var _totalTime; var _soundHolder; var _autoPlay; var _pollId; var _autoSize; var _aspectRatio; var dispatchEvent; var _mediaType; var addEventListener; static var symbolName = "MediaDisplay"; static var symbolOwner = mx.controls.MediaDisplay; var className = "MediaDisplay"; static var version = "2.0.1.78"; var clipParameters = {mediaType:"FLV",contentPath:"",totalTime:0,autoSize:true,autoPlay:true,initCuePointNames:new Array(),initCuePointTimes:new Array(),fps:30}; var _priorTime = 0; var _priorBytesLoaded = 0; var _scrubbing = false; var _fireCuePoints = true; var _enabled = true; var makeVideoVisible = false; function MediaDisplay() { super(); } function init(Void) { this.initializeParameters(); var _loc3_ = this._width; var _loc4_ = this._height; this._deadPreview._visible = false; super.init(); this.setSize(_loc3_,_loc4_,true); this.initCuePoints(); this._startingTime = 0; this._playingBeforeDisabled = false; this._started = false; this._sendCompleteEvent = false; this._fullyLoaded = false; this.makeVideoVisible = false; this.tabEnabled = false; this.tabChildren = false; this._screenAccommodator = new mx.controls.streamingmedia.ScreenAccommodator(this); } function initializeParameters() { if(this.mediaType == null) { this.mediaType = "FLV"; } if(this.totalTime == null) { this.totalTime = 0; } if(this.contentPath == null) { this.contentPath = ""; } if(this.autoPlay == null) { this.autoPlay = true; } if(this.autoSize == null) { this.autoSize = true; } if(this.aspectRatio == null) { this.aspectRatio = true; } } function initCuePoints() { this._cuePoints = new Array(); var _loc2_ = 0; while(_loc2_ < this.initCuePointNames.length && _loc2_ < this.initCuePointTimes.length) { this.addCuePoint(this.initCuePointNames[_loc2_],this.initCuePointTimes[_loc2_]); _loc2_ = _loc2_ + 1; } delete this.initCuePointNames; delete this.initCuePointTimes; this._mostRecentCuePoint = undefined; } function initMedia(switchType) { if(this.isLivePreview()) { return undefined; } var _loc2_ = this.volume; if(switchType) { this._playerImpl.stop(); } if(this.isFLV()) { if(this.isRtmp(this._contentPath)) { this._playerImpl = new mx.controls.streamingmedia.RTMPPlayer(this._contentPath,mx.controls.streamingmedia.StreamingMediaConstants.FLV_MEDIA_TYPE,this._videoHolder,this._totalTime); } else { this._playerImpl = new mx.controls.streamingmedia.FLVPlayer(this._contentPath,this._videoHolder,this._totalTime); } } else if(this.isMP3()) { if(switchType) { this.releaseVideo(); } if(this.isRtmp(this._contentPath)) { this._playerImpl = new mx.controls.streamingmedia.RTMPPlayer(this._contentPath,mx.controls.streamingmedia.StreamingMediaConstants.MP3_MEDIA_TYPE,this._videoHolder,this._totalTime); } else { this.createEmptyMovieClip("_soundHolder",10); this._playerImpl = new mx.controls.streamingmedia.MP3Player(this._contentPath,this._soundHolder); } } if(_loc2_ != undefined) { this.volume = _loc2_; } this.redraw(true); this._playerImpl.removeAllListeners(); this._playerImpl.addListener(this); this._started = false; if(!switchType) { if(this._autoPlay) { this.play(); } else { this.load(); } this.poll(true); if(this._pollId != null) { clearInterval(this._pollId); } this._pollId = setInterval(this,"poll",250); } } function draw() { if(this.isFLV()) { if(this.makeVideoVisible) { this._videoHolder._visible = true; this.makeVideoVisible = false; } if(this._autoSize) { this.assignPreferredSize(); } else if(this._aspectRatio) { var _loc4_ = this.preferredWidth; var _loc3_ = this.preferredHeight; var _loc2_ = Math.min(this.width / _loc4_,this.height / _loc3_); this.setVideoDisplaySize(_loc2_ * _loc4_,_loc2_ * _loc3_); } else { this.setVideoDisplaySize(this.width,this.height); } } } function setVideoDisplaySize(w, h) { if(this.isFLV()) { var _loc2_ = this._videoHolder._video; _loc2_._width = w; _loc2_._height = h; _loc2_._x = (this.width - _loc2_._width) / 2; _loc2_._y = (this.height - _loc2_._height) / 2; } } function get videoWidth() { var _loc2_ = undefined; if(this.isMP3()) { _loc2_ = 0; } else { _loc2_ = this._videoHolder._video._width; } return _loc2_; } function get videoHeight() { var _loc2_ = undefined; if(this.isMP3()) { _loc2_ = 0; } else { _loc2_ = this._videoHolder._video._height; } return _loc2_; } function get preferredWidth() { var _loc2_ = undefined; if(this.isMP3()) { _loc2_ = 0; } else { _loc2_ = this._videoHolder._video.width; } return _loc2_; } function get preferredHeight() { var _loc2_ = undefined; if(this.isMP3()) { _loc2_ = 0; } else { _loc2_ = this._videoHolder._video.height; } return _loc2_; } function assignPreferredSize() { this.setVideoDisplaySize(this.preferredWidth,this.preferredHeight,true); } function handlePlayer(player, status) { if(status == "start" || status == "resizeVideo") { if(!(this._parent instanceof mx.controls.MediaPlayback)) { this.makeVideoVisible = true; this.draw(); } if(this._started) { var _loc2_ = {target:this,type:"resizeVideo"}; this.dispatchEvent(_loc2_); } else { _loc2_ = {target:this,type:"start"}; this.dispatchEvent(_loc2_); if(this.isRtmp(this._contentPath)) { _loc2_ = {target:this,type:"progress"}; this.dispatchEvent(_loc2_); } this._started = true; } } else if(status == "complete") { this._sendCompleteEvent = true; } } function toString() { return "MediaDisplay: media=" + this._contentPath; } function load() { this._playerImpl.load(); } function play(startingPoint) { if(startingPoint != undefined) { this._startingTime = startingPoint; } if(this.enabled) { this._playerImpl.play(startingPoint); } else { this._playingBeforeDisabled = true; } } function pause() { this._playerImpl.pause(); } function stop() { this._playerImpl.stop(); } function get autoSize() { return this._autoSize; } function set autoSize(flag) { if(this._autoSize != flag) { this._autoSize = flag; this.invalidate(); } } function get aspectRatio() { return this._aspectRatio; } function set aspectRatio(flag) { if(this._aspectRatio != flag) { this._aspectRatio = flag; this.invalidate(); } } function get autoPlay() { return this._autoPlay; } function set autoPlay(flag) { this._autoPlay = flag; } function get playheadTime() { return this._playerImpl.getPlayheadTime(); } function set playheadTime(position) { if(position != undefined) { this._startingTime = position; } this._playerImpl.setPlayheadTime(position); } function get contentPath() { return this._contentPath; } function set contentPath(aUrl) { this.setMedia(aUrl); } function setMedia(aUrl, aType) { this._fireCuePoints = false; if(aType == null) { aType = this.deduceMediaType(aUrl); } else if(aType != mx.controls.streamingmedia.StreamingMediaConstants.FLV_MEDIA_TYPE && aType != mx.controls.streamingmedia.StreamingMediaConstants.MP3_MEDIA_TYPE) { } var _loc5_ = this._mediaType; this._mediaType = aType; var _loc7_ = this.isRtmp(this._contentPath); var _loc6_ = this.isRtmp(aUrl); this._contentPath = aUrl; this._fullyLoaded = false; this._startingTime = 0; if(!this.isLivePreview()) { if(this._contentPath == "") { this.releaseVideo(); } else if(this._playerImpl == null) { this.initMedia(); } else if(_loc5_ != this._mediaType || _loc7_ != _loc6_) { var _loc4_ = this._playerImpl.isPlaying(); this.initMedia(true); if(_loc4_) { this._playerImpl.play(0); } else { this._playerImpl.load(); } } else { this._playerImpl.setMediaUrl(aUrl); this._started = false; } } } function deduceMediaType(aUrl) { var _loc2_ = aUrl.substr(-3); if(_loc2_ == "flv" || _loc2_ == "FLV") { return "FLV"; } if(_loc2_ == "mp3" || _loc2_ == "MP3") { return "MP3"; } return this._mediaType; } function releaseVideo() { this._playerImpl.close(); this._playerImpl = null; } function isLivePreview() { return _root.contents.obj != null; } function get volume() { return this._playerImpl.getVolume(); } function set volume(aVol) { this._playerImpl.setVolume(aVol); } function get playing() { return this._playerImpl.isPlaying(); } function get bytesLoaded() { return this._playerImpl.getMediaBytesLoaded(); } function get bytesTotal() { return this._playerImpl.getMediaBytesTotal(); } function isFLV() { return this._mediaType == mx.controls.streamingmedia.StreamingMediaConstants.FLV_MEDIA_TYPE; } function isMP3() { return this._mediaType == mx.controls.streamingmedia.StreamingMediaConstants.MP3_MEDIA_TYPE; } function get mediaType() { return this._mediaType; } function set mediaType(aType) { this._mediaType = aType; } function get totalTime() { var _loc2_ = undefined; if(this._playerImpl == null) { _loc2_ = this._totalTime; } else { _loc2_ = this._playerImpl.getTotalTime(); } return _loc2_; } function set totalTime(aTime) { this._totalTime = aTime; if(this._playerImpl instanceof mx.controls.streamingmedia.FLVPlayer) { this._playerImpl.setTotalTime(aTime); } else if(this._playerImpl instanceof mx.controls.streamingmedia.RTMPPlayer) { this._playerImpl.setTotalTime(aTime); } } function getCuePoints() { return this._cuePoints; } function get cuePoints() { return this.getCuePoints(); } function setCuePoints(cp) { this._cuePoints = cp; var _loc2_ = 0; while(_loc2_ < this._cuePoints.length) { this._cuePoints[_loc2_].display = this; _loc2_ = _loc2_ + 1; } } function set cuePoints(cp) { this.setCuePoints(cp); } function getCuePoint(pointName) { var _loc3_ = null; var _loc2_ = this.getCuePointIndex(pointName); if(_loc2_ > -1) { _loc3_ = this._cuePoints[_loc2_]; } return _loc3_; } function addCuePoint(aName, aTime) { var _loc2_ = new mx.controls.streamingmedia.CuePoint(aName,aTime); this.addCuePointObject(_loc2_); } function addCuePointObject(aCuePoint) { aCuePoint.display = this; this._cuePoints.push(aCuePoint); } function removeCuePoint(aCuePoint) { var _loc2_ = this.getCuePointIndex(aCuePoint.name); if(_loc2_ > -1) { this._cuePoints.splice(_loc2_,1); } } function removeAllCuePoints() { this._cuePoints.length = 0; this._mostRecentCuePoint = undefined; } function get mostRecentCuePoint() { return this._mostRecentCuePoint; } function get mostRecentCuePointName() { return this._mostRecentCuePoint.name; } function get mostRecentCuePointTime() { return this._mostRecentCuePoint.time; } function handleEvent(ev) { if(ev.type == "click" && ev.detail == "play") { this.handlePlayEvent(ev); } else if(ev.type == "click" && ev.detail == "pause") { this.handlePauseEvent(ev); } else if(ev.type == "playheadChange") { this.handlePlayheadChangeEvent(ev); } else if(ev.type == "volume") { this.handleVolumeEvent(ev); } else if(ev.type == "scrubbing") { this.handleScrubbingEvent(ev); } else { this.handleUnrecognizedEvent(ev); } } function handlePlayEvent(ev) { this.play(); } function handleStopEvent(ev) { this.stop(); } function handlePauseEvent(ev) { this.pause(); } function handleRewindEvent(ev) { this.playheadTime = 0; } function handleFastForwardEvent(ev) { var _loc2_ = this.totalTime; this.playheadTime = _loc2_; } function handlePlayheadChangeEvent(ev) { var _loc3_ = ev.detail; var _loc2_ = _loc3_ / 100 * this.totalTime; this._fireCuePoints = this._scrubbing; this.playheadTime = _loc2_; } function handleVolumeEvent(ev) { var _loc2_ = ev.detail; this.volume = _loc2_; } function handleScrubbingEvent(ev) { this._scrubbing = ev.detail; } function handleUnrecognizedEvent(ev) { } function getCuePointIndex(pointName) { var _loc3_ = -1; var _loc2_ = 0; while(_loc2_ < this._cuePoints.length && _loc3_ == -1) { if(this._cuePoints[_loc2_].name == pointName) { _loc3_ = _loc2_; } _loc2_ = _loc2_ + 1; } return _loc3_; } function poll(first) { var _loc4_ = this.playheadTime; var _loc8_ = this.bytesLoaded; if(_loc4_ != this._priorTime) { if(this._mediaType == "MP3" && this._playerImpl.isPlaying() && !this._started) { this._playerImpl.playStarted(); var _loc9_ = this.playheadTime; if(this._startingTime - 0.1 < _loc9_ && _loc9_ < this._startingTime + 0.1) { this._started = true; var _loc10_ = {target:this,type:"start"}; this.dispatchEvent(_loc10_); } } _loc10_ = {type:"change",target:this}; this.dispatchEvent(_loc10_); } var _loc7_ = false; if(!this._fullyLoaded && this.bytesLoaded >= this.bytesTotal - 100) { this._fullyLoaded = true; this._playerImpl.mediaLoaded(); _loc7_ = true; } else if(first || _loc8_ != this._priorBytesLoaded) { _loc7_ = true; } if(_loc7_) { _loc10_ = {type:"progress",target:this}; this.dispatchEvent(_loc10_); } var _loc2_ = null; var _loc3_ = 0; while(this._fireCuePoints && _loc3_ < this._cuePoints.length) { _loc2_ = this._cuePoints[_loc3_]; if(this._priorTime < _loc2_.time && _loc4_ >= _loc2_.time || this._priorTime > _loc2_.time && _loc4_ <= _loc2_.time) { this._mostRecentCuePoint = _loc2_; _loc10_ = {type:"cuePoint",target:this,cuePointName:_loc2_.name,cuePointTime:_loc2_.time}; this.dispatchEvent(_loc10_); } _loc3_ = _loc3_ + 1; } this._fireCuePoints = true; if(this._sendCompleteEvent) { this._sendCompleteEvent = false; _loc10_ = {type:"complete",target:this}; this.dispatchEvent(_loc10_); } this._priorTime = _loc4_; this._priorBytesLoaded = _loc8_; } function isRtmp(mediaUrl) { if(mediaUrl != null) { var _loc1_ = undefined; _loc1_ = mediaUrl.toLowerCase(); return _loc1_.indexOf("rtmp") == 0; } return false; } function associateController(c) { c.addEventListener("click",this); c.addEventListener("playheadChange",this); c.addEventListener("volume",this); c.addEventListener("scrubbing",this); this.addEventListener("change",c); this.addEventListener("progress",c); this.addEventListener("complete",c); } function setSize(w, h, noEvent) { super.setSize(w,h,noEvent); this.invalidate(); } function get enabled() { return this._enabled; } function set enabled(is) { if(this._enabled == is) { return; } this._enabled = is; if(is) { if(this._playingBeforeDisabled) { this.play(); this._playingBeforeDisabled = false; } } else { this._playingBeforeDisabled = this.playing; if(this._playingBeforeDisabled && this._playerImpl instanceof mx.controls.streamingmedia.MP3Player) { this._playingBeforeDisabled = !this._playerImpl.willStop(); } this.pause(); } } function onUnload() { this._playerImpl.close(); } }