Flex2款简单FLV播放器--很经典
网上找到2款比较简单的VideoDisplay实例应用,很精简但很经典。
第一款:普通播放器,包括Play,Stop,Pause,进程拖拽显示,声音调整,全屏等功能
主要是playheadTime,VideoEvent.PLAYHEAD_UPDATE,volume的应用
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 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 video_url:String = "video/happy.flv";
- private var playPosition:Number;
- private var soundPosition:Number;
- private function playinit():void{
- hs.enabled=false;
- }
- private function flvplay(event:Event):void{
- flv_video.source=video_url;
- 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.displayState="fullScreen";
- application.width="100%";
- application.height="100%";
- }
- else{
- stage.displayState="normal";
- }
- }
- ]]-->
- </mx:Script>
- <mx:VideoDisplay id="flv_video" x="0" width="100%" height="100%" y="0" autoPlay="true" autoRewind="true"/>
- <mx:ApplicationControlBar height="20" width="100%" bottom="67" 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="49" 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="94" 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="100">
- <mx:HSlider id="hs_sound" width="82" minimum="0" maximum="1" thumbRelease="sound_thumbRelease(event)" change="sound_thumbChanges(event)" value="{flv_video.volume}" />
- </mx:ApplicationControlBar>
- <mx:ApplicationControlBar color="#EC968F">
- <mx:CheckBox label="全屏" id="fs" change="display();"/>
- </mx:ApplicationControlBar>
- </mx:ApplicationControlBar>
- </mx:Application>
第二款:外加提示点播放器
主要是cuePointManagerClass的应用。
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#FFFFFF"
- creationComplete="srv.send()"
- currentState="{vd.playing?'videoPlaying':''}">
- <mx:states>
- <mx:State name="videoPlaying">
- <mx:SetProperty target="{panel}" name="width" value="652"/>
- </mx:State>
- </mx:states>
- <mx:Script>
- <!--[CDATA[
- import mx.collections.ArrayCollection;
- import mx.events.CuePointEvent;
- private function cuePointHandler(event:CuePointEvent):void
- {
- caption.text = event.cuePointName;
- }
- private function changeHandler():void
- {
- vd.cuePointManager.removeAllCuePoints()
- vd.cuePoints = ArrayCollection(list.selectedItem.cuePoint).source;
- }
- ]]-->
- </mx:Script>
- <mx:HTTPService id="srv" url="question.xml"/>
- <mx:Panel title="Frequently Asked Questions" layout="absolute" x="20" y="20" width="320" height="282" id="panel" horizontalScrollPolicy="off"
- resizeEffect="Resize">
- <mx:List id="list" dataProvider="{srv.lastResult.questions.question}" labelField="text"
- change="changeHandler()" left="0" top="0" bottom="0" width="310"/>
- <mx:VideoDisplay id="vd" source="{list.selectedItem.video}" height="240" autoPlay="true"
- cuePointManagerClass="mx.controls.videoClasses.CuePointManager" cuePoint="cuePointHandler(event)"
- top="1" left="311" width="320"/>
- <mx:Button label="Stop" click="vd.stop()" x="566" y="8"/>
- <mx:Text id="caption" x="320" y="200" color="#FFFFFF" fontWeight="bold" height="40" width="320"/>
- </mx:Panel>
- </mx:Application>
question.xml
- <?xml version="1.0" encoding="utf-8"?>
- <questions>
- <question>
- <text>Who can apply?</text>
- <video>video/happy.flv</video>
- <cuePoint time="1" name="We accept students from a variety of programs"/>
- <cuePoint time="6" name="If your institution is not accredited"/>
- <cuePoint time="8.5" name="Contact department before applying"/>
- </question>
- <question>
- <text>How are applications evaluated?</text>
- <video>video/happy1.flv</video>
- <cuePoint time="1" name="We take a number of factors into account"/>
- <cuePoint time="6" name="GPA below 3.0?"/>
- <cuePoint time="8.5" name="Contact department before applying"/>
- </question>
- <question>
- <text>When should I provide financial information?</text>
- <video>video/happy2.flv</video>
- <cuePoint time="1" name="Financial information is not required until you have been accepted"/>
- <cuePoint time="6" name="Graduate school will send list of required documents"/>
- <cuePoint time="11" name="No need to send financial information until you have been accepted "/>
- </question>
- </questions>