Flash Builder 开发视频播放器客户端(FlvPlayer.mxml)
发布时间:2020-12-15 17:42:03 所属栏目:百科 来源:网络整理
导读:?xml version="1.0" encoding="utf-8"?s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" initialize="init(event)" mouseM
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" initialize="init(event)" mouseMove="application1_mouseMoveHandler(event)"> <fx:Script> <![CDATA[ import flash.display.StageDisplayState; import flash.events.MouseEvent; import mx.controls.Alert; import mx.core.FlexGlobals; import mx.events.FlexEvent; import mx.events.SliderEvent; import mx.events.VideoEvent; import org.osmf.events.LoadEvent; import org.osmf.events.TimeEvent; import flash.utils.Timer; import flash.events.TimerEvent; import spark.components.Button; import spark.events.TrackBaseEvent; [Embed(source="assets/play.png")] // Embed嵌入资源文件 [Bindable] private var playImage:Class; // 与定义的变量进行绑定 [Embed(source="assets/pause.png")] [Bindable] private var pauseImage:Class; private var isFullScreen:Boolean = false; //是否是全屏 private var doubleClickStrFlag:String = "click"; protected function parseTime(Time:int):String //解析时间 { var minute:int; var second:int; minute = Time/60; second = Time - (minute*60); var d:String = new String(); if(minute < 10 && second < 10) { d = "0" + minute.toString(10)+":"+ "0" + second.toString(10); } else if(minute < 10 && second >= 10) { d = "0" + minute.toString(10)+":"+ second.toString(10); } else if(minute >= 10 && second < 10) { d = minute.toString(10)+":"+ "0" + second.toString(10); } else if(minute >= 10 && second >= 10) { d = minute.toString(10)+":"+ second.toString(10); } return d; } protected function init(event:FlexEvent):void { hslider.track.alpha = 0; showtime.text = "00:00/00:00"; border.setStyle("showEffect",fade); //videodisplay.source = FlexGlobals.topLevelApplication.parameters.videoFullName; videodisplay.source = "assets/advertise.flv"; //播放源 volume.value = videodisplay.volume*50; //音量值 } protected function play_clickHandler(event:MouseEvent):void { // TODO Auto-generated method stub if(play.label== "播放") { play.label = "暂停"; canvas.visible=false; this.play.setStyle("icon",this.pauseImage); videodisplay.play(); } else if(play.label == "暂停") { play.label = "播放"; canvas.visible=true; this.play.setStyle("icon",this.playImage); videodisplay.pause(); } } protected function stop_clickHandler(event:MouseEvent):void { // TODO Auto-generated method stub videodisplay.stop(); play.label = "播放"; canvas.visible=true; this.play.setStyle("icon",this.playImage); } protected function volume_changeHandler(event:SliderEvent):void { // TODO Auto-generated method stub videodisplay.volume = volume.value/100; } protected function hslider_mouseMoveHandler(event:MouseEvent):void { // TODO Auto-generated method stub currenttime.visible = true; currenttime.x = hslider.x+hslider.mouseX; currenttime.text = parseTime(progress.mouseX/progress.width*videodisplay.duration); //当前播放时间累计 } protected function hslider_mouSEOutHandler(event:MouseEvent):void { // TODO Auto-generated method stub currenttime.visible = false; } protected function hslider_changeHandler(event:Event):void { // TODO Auto-generated method stub videodisplay.seek(hslider.value/100*videodisplay.duration); if(play.label == "播放") { play.label = "暂停"; canvas.visible=false; this.play.setStyle("icon",this.pauseImage); } } protected function hslider_thumbPressHandler(event:TrackBaseEvent):void { // TODO Auto-generated method stub videodisplay.pause(); } protected function hslider_thumbReleaseHandler(event:TrackBaseEvent):void { // TODO Auto-generated method stub videodisplay.play(); } protected function fullscreen_clickHandler(event:MouseEvent):void { // TODO Auto-generated method stub doubleClickStrFlag =event.type.toString(); if(!isFullScreen) //退出全屏 { stage.displayState=StageDisplayState.FULL_SCREEN; stage.addEventListener(FullScreenEvent.FULL_SCREEN,haha); //haha充当回调函数 videodisplay.x = 0; videodisplay.y = 0; videodisplay.width = stage.width; videodisplay.height = stage.height; full.width = stage.width; full.height = stage.height; canvas.width = stage.width; canvas.height = stage.height; borderD.y=stage.height-25; borderD.width=stage.width-1; border.width=stage.width-1; fullscreen.x=stage.width-25; volume.x=stage.width-75; voice.x=stage.width-90; showtime.x=stage.width-155; progress.x=33; hslider.x=33; progress.width=stage.width-205; hslider.width=stage.width-205; border.visible = true; currenttime.visible = false; isFullScreen = true; } else //进入全屏 { stage.displayState = StageDisplayState.NORMAL; videodisplay.x = 0; videodisplay.y = 0; videodisplay.width = 334; videodisplay.height = 285; full.width = 334; full.height = 285; canvas.width = 334; canvas.height = 285; borderD.y=259; borderD.width=333; border.width=333; progress.width=160; hslider.width=160; fullscreen.width=16; fullscreen.x=313; showtime.x=192; volume.x=264; voice.x=254; currenttime.y=-3; isFullScreen = false; } } public function haha(evn:FullScreenEvent):void { stage.displayState = StageDisplayState.NORMAL; stage.removeEventListener(FullScreenEvent.FULL_SCREEN,haha); play.visible = true; stop.visible = true; volume.visible=true; fullscreen.visible = true; showtime.visible = true; border.visible = true; progress.visible = true; hslider.visible = true; videodisplay.x = 0; videodisplay.y = 0; videodisplay.width = 334; videodisplay.height = 285; full.width = 334; full.height = 285; canvas.width = 334; canvas.height = 285; borderD.y=259; borderD.width=333; border.width=333; progress.width=160; hslider.width=160; fullscreen.width=16; fullscreen.x=313; showtime.x=192; volume.x=264; voice.x=254; currenttime.y=-3; videodisplay.x = 0; videodisplay.y =0; videodisplay.width = 334; videodisplay.height = 285; isFullScreen = false; } protected function videodisplay_doubleClickHandler(event:MouseEvent):void { // TODO Auto-generated method stub fullscreen_clickHandler(event); } protected function videodisplay_currentTimeChangeHandler(event:TimeEvent):void { // TODO Auto-generated method stub showtime.text = parseTime(videodisplay.currentTime) + "/" + parseTime(videodisplay.duration); hslider.value = videodisplay.currentTime/videodisplay.duration*100; } protected function hslider_thumbDragHandler(event:TrackBaseEvent):void { // TODO Auto-generated method stub videodisplay.seek(hslider.value); } protected function videodisplay_bytesLoadedChangeHandler(event:LoadEvent):void { // TODO Auto-generated method stub progress.setProgress(videodisplay.bytesLoaded,videodisplay.bytesTotal); } protected function videodisplay_completeHandler(event:TimeEvent):void { // TODO Auto-generated method stub play.label = "暂停"; this.play.setStyle("icon",this.pauseImage); videodisplay.play(); } protected function application1_mouseMoveHandler(event:MouseEvent):void { // TODO Auto-generated method stub if(videodisplay.width==334) { if(event.localX>0 && event.localX<334 && event.stageY>0 && event.stageY<285) { border.visible = true; return ; } else { border.visible = false; return ; } } else { if(event.stageY>stage.height-20 && event.stageY<=stage.height) { border.visible = true; return ; } else { border.visible = false; return ; } } } ]]> </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> <mx:Fade id="fade" /> <mx:Zoom id="zoom" /> </fx:Declarations> <s:VideoDisplay id="videodisplay" x="0" y="0" width="334" height="285" autoPlay="true" currentTimeChange="videodisplay_currentTimeChangeHandler(event)" autoDisplayFirstFrame="true" autoRewind="true" bytesLoadedChange="videodisplay_bytesLoadedChangeHandler(event)" complete="videodisplay_completeHandler(event)" opaqueBackground="#000000" buttonMode="true" useHandCursor="true"/> <mx:Label id="full" x="0" y="0" height="285" width="334" doubleClickEnabled="true" doubleClick="videodisplay_doubleClickHandler(event)" alpha="0"/> <mx:Canvas id="canvas" x="0" y="0" width="334" height="285" borderSkin="@Embed(source='assets/pause.swf')" visible="false" doubleClickEnabled="true" doubleClick="fullscreen_clickHandler(event)" click="play_clickHandler(event)"/> <s:BorderContainer id="borderD" x="0" y="259" width="333" height="25" backgroundColor="#000000" borderAlpha="0" backgroundAlpha="0.0"> <s:BorderContainer id="border" x="0" y="0" width="333" height="25" borderColor="#FE0000" backgroundColor="#030003" visible="false" backgroundAlpha="0.5" borderAlpha="0" > <mx:LinkButton id="play" x="1" y="4" label="暂停" height="16" width="16" fontFamily="微软雅黑" toggle="true" click="play_clickHandler(event)" alpha="1" toolTip="播放/暂停" fontSize="10" icon="@Embed(source='assets/pause.png')"/> <mx:LinkButton id="stop" x="17" y="4" label="停止" height="16" width="16" fontFamily="微软雅黑" click="stop_clickHandler(event)" toolTip="停止" fontSize="10" icon="@Embed(source='assets/stop.png')" alpha="1" toggle="true"/> <mx:LinkButton id="fullscreen" x="313" y="4" label="全屏" height="15" width="16" fontFamily="微软雅黑" click="fullscreen_clickHandler(event)" toolTip="全屏" fontSize="10" icon="@Embed(source='assets/fullscreen.png')"/> <s:TextInput id="showtime" x="192" y="3" width="63" contentBackgroundColor="#000000" fontSize="10" editable="false" fontFamily="仿宋" color="#FFFFFF" contentBackgroundAlpha="0.0" borderAlpha="1" borderVisible="false" height="15"/> <mx:ProgressBar x="33" y="9" fontSize="0" labelWidth="0" height="3" width="160" chromeColor="#000000" barSkin="mx.skins.halo.ProgressBarSkin" trackHeight="6" minimum="0" maximum="100" mode="manual" id="progress" fontFamily="微软雅黑" useHandCursor="true"/> <s:HSlider id="hslider" x="33" y="8" width="160" height="8" minimum="0" maximum="100" showDataTip="false" mouseMove="hslider_mouseMoveHandler(event)" mouSEOut="hslider_mouSEOutHandler(event)" change="hslider_changeHandler(event)" thumbPress="hslider_thumbPressHandler(event)" liveDragging="true" thumbRelease="hslider_thumbReleaseHandler(event)" useHandCursor="true" buttonMode="true" skinClass="myhslider" thumbDrag="hslider_thumbDragHandler(event)"/> <mx:HSlider id="volume" x="264" y="6" minimum="0" maximum="100" showDataTip="true" enabled="true" value="50" showTrackHighlight="true" change="volume_changeHandler(event)" height="1" width="47" visible="true"/> <mx:Image id="voice" x="254" y="6" source="assets/laba.png" width="13" height="12"/> <s:Label id="currenttime" x="33" y="-3" width="75" height="17" visible="true" fontSize="10" color="#FFFFFF" fontWeight="bold" backgroundColor="#000000" backgroundAlpha="0.0"/> </s:BorderContainer> </s:BorderContainer> </s:Application> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |