<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" preloader="com.ibsol.view.Preloader" layout="absolute" creationComplete="playinit()" width="500" height="400"> <mx:Script> <![CDATA[ import mx.events.SliderEvent; import mx.events.VideoEvent; import flash.display.Stage; private var isplaying:Boolean=false;//默認為播放狀態 private var playPosition:Number;//播放進度 private var soundPosition:Number;//聲音大小 private function playinit():void{ hs.enabled=false; } //設罷播放源 private function flvplay(event:Event):void{ var query:String = ExternalInterface.call("getFileUrl");//回調用文件路徑 if(query==null) { flv_video.source="file:///E:/PlaySource/09062001-BEGINNING.flv";//默認文件 }else{ flv_video.source=query; } hs.enabled=true; if(isplaying){ flv_video.pause(); play_btn.label="播放" }else { flv_video.play(); play_btn.label="暂停" } isplaying = !isplaying; //監聽播放進度 flv_video.addEventListener(VideoEvent.PLAYHEAD_UPDATE, progressHandler); } //顯示播放進度 private function progressHandler(event:VideoEvent):void{ hs.value=flv_video.playheadTime; } //調整時停止播放 private function thumbPress(event:SliderEvent):void{ flv_video.pause(); } //播放完成歸零 private function thumbChanges(event:SliderEvent):void{ if(flv_video.playheadTime == -1){ hs.value = 0; return; } playPosition = hs.value;//保正播放徑度統一 } //調整播放進度 private function thumbRelease(event:SliderEvent):void{ flv_video.playheadTime = playPosition; if(isplaying){ flv_video.play(); }else{ flv_video.pause(); } } //調整聲音 private function sound_thumbChanges(event:SliderEvent):void{ soundPosition = hs_sound.value; } private function sound_thumbRelease(event:SliderEvent):void{ flv_video.volume = soundPosition; } //格式化時間 private function formatTimes(value:int):String{ var result:String = (value % 60).toString(); if (result.length == 1){ result = Math.floor(value / 60).toString() + ":0" + result; }else { result = Math.floor(value / 60).toString() + ":" + result; } return result; } //切換全屏顯示 private function display():void { if(fs.selected)//全屏 { stage.fullScreenSourceRect =new Rectangle(flv_video.x,flv_video.y,flv_video.width,flv_video.height); stage.displayState =StageDisplayState.FULL_SCREEN; } else { stage.displayState = StageDisplayState.NORMAL;//恢復正常 fs.selected=false; } } ]]> </mx:Script> <mx:VideoDisplay id="flv_video" x="0" width="100%" height="330" y="0" source="{Application.application.parameters.file}" autoPlay="true" autoRewind="true" bufferTime="0.5" maintainAspectRatio="true"/> <mx:ApplicationControlBar height="20" width="100%" bottom="53" x="0" horizontalAlign="center"> <mx:HSlider id="hs" fillColors="#000099, #0000ff, #ffffff, #eeeeee" showTrackHighlight="true" minimum="0" maximum="{flv_video.totalTime}" thumbPress="thumbPress(event)" thumbRelease="thumbRelease(event)" change="thumbChanges(event)" width="90%" horizontalCenter="0"/> </mx:ApplicationControlBar> <mx:ApplicationControlBar width="100%" height="38" horizontalAlign="center" x="0" bottom="10"> <mx:ApplicationControlBar width="123" cornerRadius="15"> <mx:Button id="play_btn" click="flvplay(event)" label="播放" cornerRadius="13"/> <mx:Button id="stop_btn" label="停止" cornerRadius="13" click="flv_video.stop();play_btn.label='播放';hs.enabled=false;" /> </mx:ApplicationControlBar> <mx:ApplicationControlBar width="95" cornerRadius="15"> <mx:Label id="playtime" text="{formatTimes(flv_video.playheadTime)} : {formatTimes(flv_video.totalTime)}" color="#ffffff" width="77"/> </mx:ApplicationControlBar> <mx:ApplicationControlBar cornerRadius="15" width="130"> <mx:Label id="sound" text="声音" width="29" fontWeight="bold" fontSize="11"/><mx:HSlider id="hs_sound" width="86" minimum="0" maximum="1" thumbRelease="sound_thumbRelease(event)" change="sound_thumbChanges(event)" value="{flv_video.volume}" fillAlphas="[0.6, 1.0, 1.0, 1.0]"/> </mx:ApplicationControlBar> <mx:ApplicationControlBar color="#F1EFE5"> <mx:CheckBox label="全屏" id="fs" change="display();"/> </mx:ApplicationControlBar> </mx:ApplicationControlBar> </mx:Application>