注意:全屏功能,需要在html写代码,具体代码 :参考关于flex全屏问题 <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" xmlns:file="file.*" paddingTop="20"> <mx:Style source="css/Styles.css"/> <mx:XMLList id="mystates"> <flv label="所有视频"> <flv label="cafe_townsend_home.flv" source="flv/cafe_townsend_home.flv"/> </flv> </mx:XMLList> <mx:HDividedBox width="90%" height="90%"> <mx:TitleWindow id="twLeft" width="20%" title="视频列表" height="90%" showCloseButton="true" styleName="TitleWindow" close="minWindow()" creationComplete="init()"> <mx:Tree id="tree" width="100%" height="100%" labelField="@label" dataProvider="{mystates}" itemClick="chooseFlv(event)" doubleClickEnabled="true" doubleClick="itemPlay(event)"> </mx:Tree> </mx:TitleWindow> <mx:TitleWindow width="80%" height="90%" title="自己的播放器"> <mx:VideoDisplay width="100%" height="90%" id="vd" autoPlay="false" autoRewind="true"/> <mx:HBox width="100%" height="35" paddingLeft="5"> <mx:Button label="Play" click="paly()" id="btnPlay" toolTip="播 放"/> <mx:Button label="Stop" click="stop()" id="btnStop" toolTip="停 止 "/> <mx:Canvas height="34" width="500"> <mx:HSlider height="20" showDataTip="true" width="480" id="hsLength" minimum="0" maximum="{vd.totalTime}" allowTrackClick="true" thumbRelease="thumbR(event)" thumbPress="thumbP(event)" thumbSkin="@Embed(source='images/thum_skin.png')" trackSkin="@Embed(source='images/bg_slider.png')"/> <mx:Label text="音量:" x="337" y="14"/> <mx:HSlider id="hsSound" width="100" y="16" x="381" minimum="0" maximum="1" thumbSkin="@Embed(source='images/thum_skin.png')" snapInterval="0.2" allowTrackClick="true" value="0.6" change="changeSound()"/> <mx:Label id="lblTime" x="10" y="14" text="{formatTimes(vd.playheadTime)} : {formatTimes(vd.totalTime)}" color="blue" width="102"/> </mx:Canvas> <mx:Button label="Full" click="fullScreen()" toolTip="全屏"/> </mx:HBox> </mx:TitleWindow> </mx:HDividedBox> <mx:Script> <!--[CDATA[ import mx.events.SliderEvent; import mx.events.VideoEvent; import mx.controls.Alert; import mx.events.ListEvent; private var w:int; private function init():void{ w=twLeft.width; } private var flvUrl:String; /* 获取选择的文件,赋值给播放器做为源 */ private function chooseFlv(event:ListEvent):void{ //Alert.show(Tree(event.target).selectedItem.@source); flvUrl=Tree(event.target).selectedItem.@source; this.vd.source=flvUrl; } //也可以双击播放 private function itemPlay(event:MouseEvent):void{ this.vd.source=flvUrl; this.vd.play(); } /*播放或暂停 */ private function paly():void{ if(vd.playing){ this.btnPlay.label="Play"; this.vd.pause(); }else{ this.vd.play(); this.btnPlay.label="Pause"; } vd.addEventListener(VideoEvent.PLAYHEAD_UPDATE,videoHandle); } //stop play private function stop():void{ if(vd.playing){ this.vd.stop(); this.btnPlay.label="Play"; } } private function videoHandle(event:VideoEvent):void{ this.hsLength.value=vd.playheadTime; if(hsLength.value==hsLength.maximum){ this.btnPlay.label="Play"; } } //改变音量 private function changeSound():void{ vd.volume=this.hsSound.value; } //全屏 private function fullScreen():void{ //stage.displayState="fullScreen"; stage.displayState=StageDisplayState.FULL_SCREEN; twLeft.width=twLeft.minWidth; } //格式化时间 private function formatTimes(value:int):String{ var result:String = (value % 60).toString(); trace(value+"--"+result); if (result.length == 1){ result = Math.floor(value / 60).toString() + ":0" + result; } else { result = Math.floor(value / 60).toString() + ":" + result; } return result; } /* 按下滑块,暂停播放 */ private function thumbP(event:SliderEvent):void{ vd.pause(); } /* 松开滑块,继续播放 */ private function thumbR(event:SliderEvent):void{ vd.playheadTime=hsLength.value; if(vd.playing){ vd.play(); }else{ vd.pause(); } } /*折叠播放列表*/ private function minWindow():void{ if(twLeft.width==twLeft.minWidth){ twLeft.width=w; }else{ twLeft.width=twLeft.minWidth; } } ]]--> </mx:Script> </mx:Application>