首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

flv播放器全屏后按ESC键退出有关问题求教

2012-12-31 
flv播放器全屏后按ESC键退出问题求教本帖最后由 haokonga 于 2009-11-17 21:32:24 编辑初学FLEX,做的FLV播

flv播放器全屏后按ESC键退出问题求教
本帖最后由 haokonga 于 2009-11-17 21:32:24 编辑 初学FLEX,做的FLV播放器,实现了一些基本功能。貌似ADOBE设定的全屏按ESC键退出,通过捕获state的状态可以更改。但是IE8.0貌似会焦点丢失,有时候需要鼠标点击重新锁定才能实现ESC退出全屏。其他像FF,opera测试正常。望高手解答,如何解决。



<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()" 
width="100%" height="100%" creationComplete="videoserver.send()" 
 backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#3A3333, #3A3333]">
<mx:Script>
  <![CDATA[
  import mx.events.DataGridEvent;
    import mx.events.SliderEvent; 
    import mx.events.VideoEvent; 
    import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;

 private var isFull:Boolean = true;
 private var isBegin:Boolean = true;
 



 
     private function playingMove(event:VideoEvent):void{
        my_hs.value = flv_video.playheadTime;
        my_hs.maximum = flv_video.totalTime;    
  //   if(isFull == false)   
    //   if(mouseY*1.5 > ( Application.application.height)){
       my_canvas.visible = true;
     //  my_canvas.x = Application.application.width - 395;
     //  my_canvas.y = Application.application.height - 113;
       
      // }
      // else
      // my_canvas.visible = false;
   }

   private function displayStateChange():void  
   {  
   //flv_video.pause();
   //  if(flv_video.playing == true)
   stage.addEventListener(FullScreenEvent.FULL_SCREEN ,fullScreenHandler);
   
     if(isFull == true)  {  
     
     stage.displayState = StageDisplayState.FULL_SCREEN;  
/*        flv_video.x = 0;
       flv_video.y = 0;
       flv_video.width = Application.application.width;
       flv_video.height = Application.application.height;      
       my_canvas.visible = false;
       isFull = false; */
       
       
    }
     else{  
      
     stage.displayState = StageDisplayState.NORMAL;  
 /*       flv_video.x = 2;
       flv_video.y = 2;
       flv_video.width = 400;


       flv_video.height = 221;
       my_canvas.x = 4;
       my_canvas.y = 221;
       isFull = true; */
     }   
      //  flv_video.setFocus();
        
   } 
  
  private function fullScreenHandler(event:FullScreenEvent):void
{

   if (event.fullScreen)
{
//全屏状态 
       flv_video.x = 0;
       flv_video.y = 0;
       flv_video.width = Application.application.width;
       flv_video.height = Application.application.height;
           my_canvas.x = 4;
       my_canvas.y = 621;   
     //  my_canvas.visible = false;
         
       isFull = false;
        
}
else

//非全屏状态
       flv_video.x = 2;
       flv_video.y = 2;
       flv_video.width = 400;
       flv_video.height = 221;
       my_canvas.x = 4;
       my_canvas.y = 221;
 
       isFull = true;

}
   
}

   private var playPosition:Number;
   private var IsTrack:Boolean = true;
   //进度条改变后,得到的值赋予PLAYPOSITION;
   private function thumbChanges(event:SliderEvent):void{
    if(flv_video.playheadTime == -1)
      {
my_hs.value = 0;
return;
  }
    playPosition = my_hs.value;
    if(IsTrack == true)
    flv_video.playheadTime = my_hs.value;
    }

    //放开进度条,再把PLAYPOSITION的值发给播放器;
    private function thumbRelease(event:SliderEvent):void{
    IsTrack = !IsTrack;
    flv_video.playheadTime = playPosition;
    flv_video.play();
    }
    //播放器监听事件,从FLV_VIDEO里不停的得到值然后传输给HSLIDER
    private function progressHandler(event:VideoEvent):void{
    my_hs.value = flv_video.playheadTime;
    }
    
    //拉动进度条
    private function thumbPress(event:SliderEvent):void{
    IsTrack = !IsTrack;
    flv_video.pause();
    }
    
    [Bindable]
    private var _video:ArrayCollection;  


    [Bindable]
    private var dfsource:String;
    
    private function readXml(event:ResultEvent):void{
    
    _video = event.result.videos.video;   
    dfsource = "video/" + _video.getItemAt(0).filename;
    } 
  
    //实现播放按钮           
private var isPlay:Boolean = true;
    
    private function flvplay(event:Event,num:int):void{
flv_video.source="video/" + _video.getItemAt(num).filename;
  if(isPlay == true){
    flv_video.play();
    play.label = "Pause";
      }
      else{
        flv_video.pause();
    play.label = "Play";
      }
        isPlay = !isPlay;
    flv_video.addEventListener(VideoEvent.PLAYHEAD_UPDATE, progressHandler);        
    }

    //实现静音
    [Bindable]
    private var mvolume:Number;
    private var ismute:Boolean= true;
    
    private function mutevolume():void{
    if(ismute == false)
      {
    flv_video.volume = mvolume;
      }
    else
      {
    mvolume = flv_video.volume;
    flv_video.volume = 0.0;
      }
      ismute = !ismute;
   }
   
   //后一曲
   private function next(e:MouseEvent):void{
   videoGrid.selectedIndex++;
   flv_video.source="video/" + _video.getItemAt(videoGrid.selectedIndex).filename;
    if(isBegin == false)
    flv_video.playheadTime = 0.0;
   flv_video.play();
   if(isBegin == true)
   flv_video.playheadTime = 0.0;
   play.label = "Pause";
    isPlay = false;
    if(isBegin == true)
    isBegin = false;
    flv_video.addEventListener(VideoEvent.PLAYHEAD_UPDATE, progressHandler);
   }
   
   //前一曲
   private function previous(e:MouseEvent):void{
   if(videoGrid.selectedIndex>0)
   videoGrid.selectedIndex--;
   
   flv_video.source="video/" + _video.getItemAt(videoGrid.selectedIndex).filename;
    if(isBegin == false)
    flv_video.playheadTime = 0.0;
   flv_video.play();
   if(isBegin == true)


   flv_video.playheadTime = 0.0;
   play.label = "Pause";
    isPlay = false;
    if(isBegin == true)
    isBegin = false;
    flv_video.addEventListener(VideoEvent.PLAYHEAD_UPDATE, progressHandler);
   }
    
    //选中一个列表项目后因为会自动播放,所以需要改变play按钮
    private function itemclick(e:Event):void{
    
    flv_video.source="video/" + _video.getItemAt(videoGrid.selectedIndex).filename; 
    if(isBegin == false)
    flv_video.playheadTime = 0.0;
    flv_video.play();
    if(isBegin == true)
    flv_video.playheadTime = 0.0;
    play.label="Pause";
    isPlay = false;
    if(isBegin == true)
    isBegin = false;
    flv_video.addEventListener(VideoEvent.PLAYHEAD_UPDATE, progressHandler);
    }
    
    private function init():void{
    flv_video.addEventListener(KeyboardEvent.KEY_UP, Window_keyDown);
    }
     private function Window_keyDown(evt:KeyboardEvent):void { 
    
if (evt.charCode == Keyboard.ESCAPE) { 

 if(isFull == false){
   stage.displayState = StageDisplayState.NORMAL;  
       flv_video.x = 2;
       flv_video.y = 2;
       flv_video.width = 400;
       flv_video.height = 221;
       my_canvas.x = 4;
       my_canvas.y = 221;  
       isFull = true;  
}  
    } 
}  

  ]]>
</mx:Script>
 
<!--通过HTTPSERVICE来分析XML,然后得出RESULT,结果的反馈在SCRIPT里 -->
<mx:HTTPService id="videoserver" url="video/videolist.xml"  result="readXml(event)"/>
    
<mx:VideoDisplay id="flv_video"  playheadUpdate="playingMove(event)"  x="1" y="2" width="400" height="221"
  autoPlay="false"  autoRewind="true"  
  maintainAspectRatio="true" volume="1.0" source="{dfsource}"
  autoBandWidthDetection="true"  idleTimeout="10000" live="true"
  complete="videoGrid.selectedIndex++;flvplay(event,videoGrid.selectedIndex);flv_video.play()" />
 <mx:Canvas x="4" y="221" width="397" height="112" id="my_canvas">
  <mx:Button x="10" y="10" label="上一段" click="previous(event)" id="previousbtn"/>
  <mx:HSlider  minimum="0"  id="my_hs" maximum="{flv_video.totalTime}"
   change="thumbChanges(event)"   x="77" y="20"  
    thumbRelease="thumbRelease(event)"
    thumbPress="thumbPress(event)" 


    allowTrackClick="true"    liveDragging="true" />
  <mx:Button x="238" y="10" label="下一段" click="next(event)" id="nextbtn"/>
  <mx:Button  label="Play" click="flvplay(event,videoGrid.selectedIndex)" x="10" y="40"  id="play"/>
  <mx:Button x="77" y="40" label="Stop" click="flv_video.stop()" id="stop"/>
  <mx:Label x="13" y="70" text="volume" id="vollable" color="#ABAEAF"/>
  <mx:HSlider x="70" y="68" minimum="0.0" maximum="1.0" width="158" value="{flv_video.volume}" change="flv_video.volume=vol.value" id="vol"/>
  <mx:Button x="147" y="40" label="Mute"  id="mute" click="mutevolume()"/>
  <mx:Button x="239" y="40" label="Full" click="displayStateChange()" id="full" width="55"/>
  <mx:DataGrid x="300" y="5" id="videoGrid" dataProvider="{_video}"
  itemClick="itemclick(event)" selectedIndex="0"  width="97" height="102">
  <mx:columns>
  <mx:DataGridColumn headerText="视频列表" dataField="filename"/>
  <mx:DataGridColumn headerText="Column 2" dataField="col2" visible="false"/>
  <mx:DataGridColumn headerText="Column 3" dataField="col3" visible="false"/>
  </mx:columns>
  </mx:DataGrid>
 </mx:Canvas>
 
</mx:Application>
  <mx:Button x="239" y="40" label="Full" click="displayStateChange()" id="full" width="55"/>
  <mx:DataGrid x="300" y="5" id="videoGrid" dataProvider="{_video}"
  itemClick="itemclick(event)" selectedIndex="0"  width="97" height="102">
  <mx:columns>
  <mx:DataGridColumn headerText="视频列表" dataField="filename"/>
  <mx:DataGridColumn headerText="Column 2" dataField="col2" visible="false"/>
  <mx:DataGridColumn headerText="Column 3" dataField="col3" visible="false"/>
  </mx:columns>
  </mx:DataGrid>
 </mx:Canvas>
 
</mx:Application>
[解决办法]
没写过,学习了

热点排行