[flex]flex视频监控分区多屏播放器源代码
[flex]flex视频监控分区多屏播放器源代码
主应用(BXPlayer.mxml)
- <?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"
- xmlns:component="com.bx.component.*"
- width="960" height="530" initialize="init(event)" >
- <fx:Script>
- <![CDATA[
- import com.bx.component.FLVideo;
- import com.bx.util.EventArgExtend;
- import com.bx.util.FullScreenUtil;
- import com.bx.util.RightClickManager;
- import mx.controls.Alert;
- import mx.controls.Menu;
- import mx.core.UIComponent;
- import mx.events.CloseEvent;
- import mx.events.FlexEvent;
- import mx.events.MenuEvent;
- //视频Vector数组
- private var fVector:Vector.<FLVideo> = new Vector.<FLVideo>();
- [Bindable]
- private var sqrScreens:int = 1;
- [Bindable]
- private var text:String;
- private function playVideo(videoHost:String, videoName:String):void{
- for(var i:int = 0; i < fVector.length; i++){
- var flv:FLVideo = fVector[i];
- if(!flv.isConStream){
- flv.init(videoHost, videoName);
- break
- }
- }
- }
- protected var rightClickRegisted:Boolean = false;
- //初始化
- protected function init(event:FlexEvent):void
- {
- ExternalInterface.addCallback("playVideo",playVideo);
- if (!rightClickRegisted)
- {
- RightClickManager.regist();
- rightClickRegisted = true;
- }
- this.addFLVideo(49); //添加视频
- flvContainer.addElement(fVector[0]); //初始化第一屏
- }
- //切换屏幕
- protected function changeScreen(event:MouseEvent):void
- {
- //初始化选择框的位置
- selectRect.width = 0;
- selectRect.height = 0;
- //获取几屏
- var screen:int = int(Button(event.currentTarget).label);
- sqrScreens = Math.sqrt(screen);
- flvContainer.removeAllElements(); //删除所有元素
- for(var i:int = 0; i < screen; i++){
- var flVideo:FLVideo = fVector[i];
- flVideo.toolTip = flVideo.name;
- flvContainer.addElement(flVideo);
- }
- }
- //初始化视频窗口
- private function addFLVideo(num:int):void{
- var flVideo:FLVideo = null;
- for(var i:int = 0; i < num; i++){
- flVideo = new FLVideo();
- flVideo.name = "第" + i + "个";
- flVideo.doubleClickEnabled = true; //允许双击
- //视频双击全屏事件
- flVideo.addEventListener(MouseEvent.DOUBLE_CLICK,dbFullScreen);
- //视频单击事件
- flVideo.addEventListener(MouseEvent.CLICK, flVideoClick);
- //鼠标右键事件
- flVideo.addEventListener(RightClickManager.RIGHT_CLICK, EventArgExtend.create(rightClickHandler,flVideo));
- flVideo.addEventListener(MouseEvent.MOUSE_OVER, overHandle);
- fVector.push(flVideo);
- }
- }
- private var menu:Menu;
- //控件右击事件
- private function rightClickHandler(event:ContextMenuEvent, ...arg):void{
- removeMenu();
- initMenu(arg[0]);
- }
- //删除右键菜单
- private function removeMenu():void
- {
- if(menu!=null)
- {
- menu.hide();
- menu.removeEventListener(MenuEvent.ITEM_CLICK,menuItemSelected);
- menu=null;
- }
- }
- //生成右键菜单
- private function initMenu(flVideo:FLVideo):void
- {
- menu = Menu.createMenu(this, createMenuItems(), false);
- //menu.iconField="itemIcon";//右键菜单的图标
- //menu.labelField="label"; //右键菜单的名称
- menu.variableRowHeight = true;
- menu.width=120;
- menu.addEventListener(MenuEvent.ITEM_CLICK, EventArgExtend.create(menuItemSelected, flVideo)); //右键菜单的事件
- var point:Point = new Point(mouseX,mouseY);
- point = localToGlobal(point);
- menu.show(point.x,point.y); //显示右键菜单
- }
- //创建菜单项
- private function createMenuItems():Array
- {
- var menuItems:Array = new Array();
- var menuItem1:Object = new Object;
- menuItem1.label = '查看URL'; //菜单项名称
- //menuItem.itemIcon = this.menu_SX;//菜单项图标
- var menuItem2:Object = new Object;
- menuItem2.label = '关闭'; //菜单项名称
- menuItems.push(menuItem1);
- menuItems.push(menuItem2);
- return menuItems;
- }
- //菜单项点击事件
- private function menuItemSelected(event:MenuEvent, ...arg):void
- {
- var menuItem:Object = event.menu.selectedItem as Object;
- var flVideo:FLVideo = arg[0];
- if(flVideo.isConStream){
- switch(menuItem.label){
- case "查看URL":
- Alert.show("视频URL: " + flVideo.videoHost + "/" + flVideo.videoName)
- break;
- case "关闭":
- flVideo.close();
- break;
- }
- }
- }
- private function dbFullScreen(event:MouseEvent):void{
- this.fullScreen(event.currentTarget as UIComponent);
- }
- //全屏代码
- private function fullScreen(displayObject:UIComponent):void{
- if(FullScreenUtil.isFullScreen){
- FullScreenUtil.exitFullScreen();
- //初始化选择框的位置
- selectRect.width = 0;
- selectRect.height = 0;
- }else{
- FullScreenUtil.goFullScreen();
- // 加入要全屏的对像.videoDisplay
- FullScreenUtil.addChild(displayObject, true, true, true);
- }
- }
- //点击视频窗口的时候重新画一个矩形包围视频
- private var closeVideo:FLVideo;
- private function flVideoClick(event:MouseEvent):void{
- var obj:FLVideo = event.currentTarget as FLVideo;
- selectRect.x = obj.x + 2;
- selectRect.y = obj.y + 2;
- selectRect.width = obj.width;
- selectRect.height = obj.height;
- closeVideo = obj;
- }
- private function overHandle(event:MouseEvent):void{
- text = event.currentTarget.name + ": (" + event.currentTarget.x + "," + event.currentTarget.y + "),(" + event.currentTarget.width
- + "," + event.currentTarget.height + ")";
- }
- private function close(event:MouseEvent):void
- {
- Alert.show(flvContainer.numChildren + "," + flvContainer.numElements);
- }
- protected function clickPlay(event:MouseEvent):void
- {
- // TODO Auto-generated method stub
- closeVideo.init("rtmp://42.121.0.108:9122/RpServer", "S1304180142");
- }
- ]]>
- </fx:Script>
- <fx:Declarations>
- <!-- Place non-visualelements (e.g., services, value objects) here -->
- </fx:Declarations>
- <s:BorderContainer id="flvContainer" width="960" height="480" backgroundColor="#000000"
- borderWeight="2" borderColor="#000000">
- <s:layout>
- <s:TileLayout verticalGap="2" horizontalGap="2" requestedColumnCount="{sqrScreens}" requestedRowCount="{sqrScreens}" columnAlign="justifyUsingWidth" rowAlign="justifyUsingHeight"/>
- </s:layout>
- </s:BorderContainer>
- <s:BorderContainer id="bd" y="480" width="960" height="50" borderVisible="false" backgroundColor="#E9E8EA">
- <s:HGroup x="5" y="5">
- <s:Button name="one" label="1" click="changeScreen(event)"/>
- <s:Button name="two" label="4" click="changeScreen(event)"/>
- <s:Button name="three" label="9" click="changeScreen(event)"/>
- <s:Button name="four" label="16" click="changeScreen(event)"/>
- <s:Button name="five" label="25" click="changeScreen(event)"/>
- <s:Button name="six" label="36" click="changeScreen(event)"/>
- <s:Button name="six" label="49" click="changeScreen(event)"/>
- <!--<s:Button name="six" label="64" click="changeScreen(event)"/>
- <s:Button name="six" label="81" click="changeScreen(event)"/>-->
- <s:Button label="全屏" click="fullScreen(flvContainer);"/>
- <s:Button label="播放" click="clickPlay(event)"/>
- <s:Label id="label" text="{text}"/>
- </s:HGroup>
- </s:BorderContainer>
- <s:Rect id="selectRect">
- <s:stroke>
- <s:SolidColorStroke color="0xffdd22" weight="2"/>
- </s:stroke>
- </s:Rect>
- </s:Application>
热门文章推荐
- [flex]flex视频监控分区多屏播放器源代码
- [FLEX]Flex4制作Flv视频播放器
- [Flex]flex做的加载进度条loading源代码实例
- [Flex]浏览器chromeFlash安全沙箱有冲突错误的解决办法
- [Flex]as3.0检测当前摄像头状态(占用,没有,正常)三种状态
- [Flex]Flex截图功能的实现与代码实例
- [Flex]使用控件MenuBar添加一个菜单 在子菜单点击时执行事件
- [Flex]Flex数组的使用及定义方法中使用可变参数代码示例
请稍候...