·您当前的位置:首页 > 技术教程 > Flex技术 >

[flex]flex视频监控分区多屏播放器源代码

时间:2014-02-19 10:10blog.csdn.net
[flex]flex视频监控分区多屏播放器源代码

主应用(BXPlayer.mxml)

  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
  3.                xmlns:s="library://ns.adobe.com/flex/spark" 
  4.                xmlns:mx="library://ns.adobe.com/flex/mx" 
  5.                xmlns:component="com.bx.component.*" 
  6.                width="960" height="530" initialize="init(event)" >   
  7.     <fx:Script>   
  8.         <![CDATA[  
  9.             import com.bx.component.FLVideo; 
  10.             import com.bx.util.EventArgExtend; 
  11.             import com.bx.util.FullScreenUtil; 
  12.             import com.bx.util.RightClickManager; 
  13.              
  14.             import mx.controls.Alert; 
  15.             import mx.controls.Menu; 
  16.             import mx.core.UIComponent; 
  17.             import mx.events.CloseEvent; 
  18.             import mx.events.FlexEvent; 
  19.             import mx.events.MenuEvent; 
  20.             //视频Vector数组 
  21.             private var fVector:Vector.<FLVideo> = new Vector.<FLVideo>(); 
  22.             [Bindable] 
  23.             private var sqrScreens:int = 1; 
  24.             [Bindable] 
  25.             private var text:String; 
  26.              
  27.             private function playVideo(videoHost:String, videoName:String):void{ 
  28.                 for(var i:int = 0; i < fVector.length; i++){ 
  29.                     var flv:FLVideo = fVector[i]; 
  30.                     if(!flv.isConStream){ 
  31.                         flv.init(videoHost, videoName); 
  32.                         break 
  33.                     } 
  34.                 } 
  35.             } 
  36.             protected var rightClickRegisted:Boolean = false; 
  37.              
  38.             //初始化 
  39.             protected function init(event:FlexEvent):void 
  40.             { 
  41.                 ExternalInterface.addCallback("playVideo",playVideo); 
  42.                 if (!rightClickRegisted)   
  43.                 {   
  44.                     RightClickManager.regist();   
  45.                     rightClickRegisted = true;   
  46.                 }  
  47.                  
  48.                 this.addFLVideo(49);  //添加视频 
  49.                 flvContainer.addElement(fVector[0]);  //初始化第一屏 
  50.             } 
  51.              
  52.             //切换屏幕 
  53.             protected function changeScreen(event:MouseEvent):void 
  54.             { 
  55.                 //初始化选择框的位置 
  56.                 selectRect.width = 0;  
  57.                 selectRect.height = 0; 
  58.                 //获取几屏 
  59.                 var screen:int = int(Button(event.currentTarget).label); 
  60.                 sqrScreens = Math.sqrt(screen); 
  61.                 flvContainer.removeAllElements(); //删除所有元素 
  62.                 for(var i:int = 0; i < screen; i++){ 
  63.                     var flVideo:FLVideo = fVector[i]; 
  64.                     flVideo.toolTip = flVideo.name; 
  65.                     flvContainer.addElement(flVideo); 
  66.                 } 
  67.             } 
  68.              
  69.             //初始化视频窗口 
  70.             private function addFLVideo(num:int):void{ 
  71.                 var flVideo:FLVideo = null; 
  72.                 for(var i:int = 0; i < num; i++){ 
  73.                     flVideo = new FLVideo(); 
  74.                     flVideo.name = "第" + i + "个"; 
  75.                     flVideo.doubleClickEnabled = true; //允许双击 
  76.                     //视频双击全屏事件 
  77.                     flVideo.addEventListener(MouseEvent.DOUBLE_CLICK,dbFullScreen); 
  78.                     //视频单击事件 
  79.                     flVideo.addEventListener(MouseEvent.CLICK, flVideoClick); 
  80.                     //鼠标右键事件 
  81.                     flVideo.addEventListener(RightClickManager.RIGHT_CLICK, EventArgExtend.create(rightClickHandler,flVideo)); 
  82.                     flVideo.addEventListener(MouseEvent.MOUSE_OVER, overHandle); 
  83.                     fVector.push(flVideo); 
  84.                 } 
  85.             } 
  86.              
  87.             private var menu:Menu; 
  88.             //控件右击事件 
  89.             private function rightClickHandler(event:ContextMenuEvent, ...arg):void{ 
  90.                 removeMenu(); 
  91.                 initMenu(arg[0]); 
  92.             } 
  93.             //删除右键菜单 
  94.             private function removeMenu():void  
  95.             {   
  96.                 if(menu!=null)   
  97.                 {   
  98.                     menu.hide(); 
  99.                     menu.removeEventListener(MenuEvent.ITEM_CLICK,menuItemSelected);   
  100.                     menu=null;   
  101.                 }   
  102.             } 
  103.              
  104.             //生成右键菜单 
  105.             private function initMenu(flVideo:FLVideo):void 
  106.             { 
  107.                 menu = Menu.createMenu(this, createMenuItems(), false); 
  108.                 //menu.iconField="itemIcon";//右键菜单的图标 
  109.                 //menu.labelField="label";  //右键菜单的名称  
  110.                 menu.variableRowHeight = true;      
  111.                 menu.width=120; 
  112.                 menu.addEventListener(MenuEvent.ITEM_CLICK, EventArgExtend.create(menuItemSelected, flVideo));  //右键菜单的事件 
  113.                 var point:Point = new Point(mouseX,mouseY);   
  114.                 point = localToGlobal(point);    
  115.                 menu.show(point.x,point.y);  //显示右键菜单 
  116.             } 
  117.              
  118.             //创建菜单项 
  119.             private function createMenuItems():Array   
  120.             {   
  121.                  
  122.                 var menuItems:Array = new Array(); 
  123.                 var menuItem1:Object = new Object;   
  124.                 menuItem1.label = '查看URL'; //菜单项名称 
  125.                 //menuItem.itemIcon = this.menu_SX;//菜单项图标 
  126.                 var menuItem2:Object = new Object;   
  127.                 menuItem2.label = '关闭'; //菜单项名称 
  128.                 menuItems.push(menuItem1); 
  129.                 menuItems.push(menuItem2); 
  130.                 return menuItems;   
  131.             } 
  132.              
  133.             //菜单项点击事件 
  134.             private function menuItemSelected(event:MenuEvent, ...arg):void 
  135.             { 
  136.                 var menuItem:Object = event.menu.selectedItem as Object; 
  137.                 var flVideo:FLVideo = arg[0]; 
  138.                 if(flVideo.isConStream){ 
  139.                     switch(menuItem.label){ 
  140.                         case "查看URL": 
  141.                             Alert.show("视频URL: " + flVideo.videoHost + "/" + flVideo.videoName) 
  142.                             break; 
  143.                         case "关闭": 
  144.                             flVideo.close(); 
  145.                             break; 
  146.                     } 
  147.                 } 
  148.             } 
  149.             private function dbFullScreen(event:MouseEvent):void{ 
  150.                 this.fullScreen(event.currentTarget as UIComponent); 
  151.             } 
  152.             //全屏代码 
  153.             private function fullScreen(displayObject:UIComponent):void{ 
  154.                 if(FullScreenUtil.isFullScreen){ 
  155.                     FullScreenUtil.exitFullScreen(); 
  156.                     //初始化选择框的位置 
  157.                     selectRect.width = 0;  
  158.                     selectRect.height = 0; 
  159.                 }else{ 
  160.                     FullScreenUtil.goFullScreen(); 
  161.                     // 加入要全屏的对像.videoDisplay 
  162.                     FullScreenUtil.addChild(displayObject, true, true, true); 
  163.                 } 
  164.             } 
  165.              
  166.             //点击视频窗口的时候重新画一个矩形包围视频 
  167.             private var closeVideo:FLVideo; 
  168.             private function flVideoClick(event:MouseEvent):void{ 
  169.                 var obj:FLVideo = event.currentTarget as FLVideo; 
  170.                 selectRect.x = obj.x + 2; 
  171.                 selectRect.y = obj.y + 2; 
  172.                 selectRect.width = obj.width; 
  173.                 selectRect.height = obj.height; 
  174.                 closeVideo = obj; 
  175.             } 
  176.              
  177.             private function overHandle(event:MouseEvent):void{ 
  178.                 text = event.currentTarget.name + ": (" + event.currentTarget.x + "," + event.currentTarget.y + "),(" + event.currentTarget.width 
  179.                     + "," + event.currentTarget.height + ")"; 
  180.             } 
  181.              
  182.             private function close(event:MouseEvent):void 
  183.             { 
  184.                 Alert.show(flvContainer.numChildren + "," + flvContainer.numElements); 
  185.             } 
  186.              
  187.             protected function clickPlay(event:MouseEvent):void 
  188.             { 
  189.                 // TODO Auto-generated method stub 
  190.                 closeVideo.init("rtmp://42.121.0.108:9122/RpServer", "S1304180142"); 
  191.             } 
  192.              
  193.         ]]>   
  194.     </fx:Script>   
  195.     <fx:Declarations>   
  196.         <!-- Place non-visualelements (e.g., services, value objects) here -->   
  197.     </fx:Declarations>  
  198.      
  199.     <s:BorderContainer id="flvContainer" width="960" height="480" backgroundColor="#000000" 
  200.                        borderWeight="2" borderColor="#000000"> 
  201.         <s:layout> 
  202.             <s:TileLayout verticalGap="2" horizontalGap="2" requestedColumnCount="{sqrScreens}" requestedRowCount="{sqrScreens}" columnAlign="justifyUsingWidth" rowAlign="justifyUsingHeight"/> 
  203.         </s:layout> 
  204.          
  205.     </s:BorderContainer> 
  206.     <s:BorderContainer id="bd" y="480" width="960" height="50" borderVisible="false" backgroundColor="#E9E8EA"> 
  207.         <s:HGroup x="5" y="5"> 
  208.             <s:Button name="one" label="1" click="changeScreen(event)"/> 
  209.             <s:Button name="two" label="4" click="changeScreen(event)"/> 
  210.             <s:Button name="three" label="9" click="changeScreen(event)"/> 
  211.             <s:Button name="four" label="16" click="changeScreen(event)"/> 
  212.             <s:Button name="five" label="25" click="changeScreen(event)"/> 
  213.             <s:Button name="six" label="36" click="changeScreen(event)"/> 
  214.             <s:Button name="six" label="49" click="changeScreen(event)"/> 
  215.             <!--<s:Button name="six" label="64" click="changeScreen(event)"/> 
  216.             <s:Button name="six" label="81" click="changeScreen(event)"/>--> 
  217.             <s:Button label="全屏" click="fullScreen(flvContainer);"/> 
  218.             <s:Button label="播放" click="clickPlay(event)"/> 
  219.             <s:Label id="label" text="{text}"/> 
  220.         </s:HGroup> 
  221.     </s:BorderContainer> 
  222.     <s:Rect id="selectRect"> 
  223.         <s:stroke> 
  224.             <s:SolidColorStroke color="0xffdd22" weight="2"/> 
  225.         </s:stroke>  
  226.     </s:Rect> 
  227. </s:Application>   

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器