flex学习笔记2
1 用flex做一个视频播放器
注意:如果VideoDisplay没有播放的内容时,调用stop会出现异常
Error: 1000: UNo bitrate match
先判断一下:if(flvideo.playing) flvideo.stop();
2 flex3中全屏模式
if(displayChk.selected)
{
stage.displayState="fullScreen";
}else{
stage.displayState="normal";
}
类flash.display.StageDisplayState未找到,因此直接使用字符串赋值
在flex的模板文件index.template.html中的AC_FL_RunContent调用参数中增加
'allowFullScreen','true',
在object中增加
embed下增加
allowfullscreen="true"
注意:如果VideoDisplay没有播放的内容时,调用stop会出现异常
Error: 1000: UNo bitrate match
先判断一下:if(flvideo.playing) flvideo.stop();
2 flex3中全屏模式
if(displayChk.selected)
{
stage.displayState="fullScreen";
}else{
stage.displayState="normal";
}
类flash.display.StageDisplayState未找到,因此直接使用字符串赋值
在flex的模板文件index.template.html中的AC_FL_RunContent调用参数中增加
'allowFullScreen','true',
在object中增加
xml 代码
- <param name="allowFullScreen" value="true" />
allowfullscreen="true"
才能使用全屏模式
视频播放器源码,包括音量、全屏模式、网络flv播放、定位播放
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="835" height="782" >
- <mx:Script>
- <![CDATA[
- import mx.events.SliderEvent; // 这里是导入所需要的类, 用 import 关键字, 没什么好说的
- import mx.events.VideoEvent;
- import flash.events.KeyboardEvent;
- import mx.controls.Alert;
- import flash.display.Stage;
- private var soundPosition:Number;
- // 自定义一个 playingMove() 函数, 作用: 影片播放时, id 为 " my_hs " 的HSlider 控件的值为影片的播放时间, 且最大值为影片的总时长
- private function playingMove(event:VideoEvent):void{
- my_hs.value = flvideo.playheadTime;
- my_hs.maximum=flvideo.totalTime;
- }
- // 自定义 hs_onChange() 函数, 作用: 当用户拖拉 HSlider 控件使其值发生改变时, 影片的播放头就处于其值处, 即正在播放时间处于其值处
- private function hs_onchange(event:SliderEvent):void{
- flvideo.playheadTime = event.value;
- }
- //停止
- private function stopMovie(event:MouseEvent):void{
- flvideo.stop();
- }
- //播放
- private function playMovie(event:MouseEvent):void{
- playUrl(urlText.text);
- }
- //暂停
- private function pauseMovie(event:MouseEvent):void{
- flvideo.pause();
- }
- //下拉框
- private function onChangeUrl(event:KeyboardEvent):void{
- trace(event.keyCode);
- if(event.keyCode==13){
- playUrl(urlText.text);
- }
- }
- private function playUrl(url:String):void
- {
- if(flvideo.playing)
- flvideo.stop();
- flvideo.source = url;
- flvideo.play();
- }
- //声音音量控制
- private function sound_thumbChanges(event:SliderEvent):void{
- soundPosition = hs_sound.value;
- }
- private function sound_thumbRelease(event:SliderEvent):void{
- flvideo.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 displayStateChange():void
- {
- if(displayChk.selected)
- {
- stage.displayState="fullScreen";
- }else{
- stage.displayState="normal";
- }
- }
- ]]>
- </mx:Script>
- <mx:XML id="xmlData" source="FlvData.xml" format="xml" />
- <mx:VideoDisplay id="flvideo" playheadUpdate="playingMove(event)" x="10" y="10" autoPlay="false" bufferTime="0.5" maintainAspectRatio="false" width="294" height="219"/>
- <mx:ControlBar id="ctrlBar" x="10" y="237" width="545" height="52">
- <mx:TextInput id="urlText" width="150" keyUp="onChangeUrl(event)" fontFamily="Arial" fontSize="12" color="#2C2B3A" enabled="true" height="26" toolTip="请输入flv文件的网络地址"/>
- <mx:Button label="Play" click="playMovie(event)"/>
- <mx:Button label="Stop" click="stopMovie(event)"/>
- <mx:Button label="pause" click="pauseMovie(event)"/>
- </mx:ControlBar>
- <mx:ControlBar id="ctrlBar0" x="10" y="297" width="545" height="52">
- <mx:Label
- text="音量"
- color="#ffffff"/>
- <!--播放器声音控制 -->
- <mx:HSlider id="hs_sound" width="80"
- minimum="0" maximum="1"
- thumbRelease="sound_thumbRelease(event)"
- change="sound_thumbChanges(event)"
- value="{flvideo.volume}" />
- <mx:CheckBox id="displayChk" label="全屏模式" change="displayStateChange()"/>
- </mx:ControlBar>
- <mx:ControlBar id="ctrlBar1" x="10" y="357" width="545" height="52">
- <mx:Label x="480" y="341" id="playtime"
- text="{formatTimes(flvideo.playheadTime)} : {formatTimes(flvideo.totalTime)}"
- color="#ffffff"/>
- <mx:HSlider minimum="0" id="my_hs" change="hs_onchange(event)" width="179"/>
- </mx:ControlBar>
- </mx:Application>