[flex]flex视频监控分区多屏播放器源代码(2)
组件(FLVideo.mxml) ? xml version = 1.0 encoding = utf-8 ? s:Group xmlns:fx = http://ns.adobe.com/mxml/2009 xmlns:s = library://ns.adobe.com/flex/spark xmlns:mx = library://ns.adobe.com/flex/mx s:la
组件(FLVideo.mxml)
- <?xml version="1.0" encoding="utf-8"?>
- <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:mx="library://ns.adobe.com/flex/mx">
- <s:layout>
- <s:BasicLayout/>
- </s:layout>
- <fx:Script>
- <![CDATA[
- import mx.controls.Alert;
- import mx.events.FlexEvent;
- import mx.events.ResizeEvent;
- private var conn:NetConnection;
- private var stream:NetStream;
- private var video:Video;
- [Bindable]
- private var _videoHost:String = ""; //视频服务器地址
- [Bindable]
- private var _videoName:String = ""; //视频名称
- [Bindable]
- private var visibleFlag:Boolean = false;
- public var isConStream:Boolean = false;
- public function set videoHost(host:String):void{
- this._videoHost = host;
- }
- public function get videoHost():String{
- return this._videoHost;
- }
- public function set videoName(name:String):void{
- this._videoName = name;
- }
- public function get videoName():String{
- return this._videoName;
- }
- //用于主应用程序调用初始化连接
- public function init(videoHost:String, videoName:String):void
- {
- // TODO Auto-generated method stub
- _videoName = videoName;
- _videoHost = videoHost;
- conn=new NetConnection;
- conn.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
- conn.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler);
- conn.client = this;
- conn.connect(videoHost); //连接Red5服务器
- }
- public function close():void{
- if(conn != null){
- conn.close();
- }
- if(stream != null){
- stream.close();
- }
- if(video != null){
- video.clear();
- }
- isConStream = false;
- }
- private function securityErrorHandler(event:SecurityErrorEvent):void{
- }
- private function asyncErrorHandler(event:AsyncErrorEvent):void{
- }
- public function onBWCheck(... arg):void
- {
- //do nothing
- }
- public function onBWDone(... arg):void {
- }
- public function onMetaData(obj:Object):void{
- trace(obj.duration);
- }
- private function netStatusHandler(event:NetStatusEvent):void{
- trace(event.info.code);
- switch(event.info.code)
- {
- case "NetConnection.Connect.Success":
- {
- visibleFlag = true; //连接成功时缓冲设为可见
- connectStream();
- break;
- }
- case "NetStream.Play.StreamNotFound":{
- Alert.show("文件不存在!","提示");
- break;
- }
- case "NetStream.Buffer.Full":{
- visibleFlag = false; //缓冲到可以播放隐藏
- break;
- }
- case "NetStream.Buffer.Empty":{
- visibleFlag = true; //获取不到缓冲流的时候显示
- break;
- }
- case "NetConnection.Connect.Closed":{
- visibleFlag = false; //关闭连接的时候显示
- break;
- }
- }
- }
- private function connectStream():void{
- stream=new NetStream(conn);
- stream.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
- stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncErrorHandler);
- stream.client = {}; //这句一定要,不然报错找不到onMetaData方法
- stream.bufferTime = 1;
- video = new Video(); //定义一个播放器
- video.width = vd.width;
- video.height = vd.height;
- video.smoothing = true;
- video.attachNetStream(stream);
- stream.play(_videoName);
- isConStream = true; //连接播放成功设为true
- vd.addChild(video);
- }
- protected function vd_resizeHandler(event:ResizeEvent):void
- {
- // TODO Auto-generated method stub
- if(video != null){
- video.width = vd.width;
- video.height = vd.height;
- // swfLoader.width =
- }
- }
- ]]>
- </fx:Script>
- <fx:Declarations>
- <!-- 将非可视元素(例如服务、值对象)放在此处 -->
- </fx:Declarations>
- <mx:VideoDisplay id="vd" width="100%" height="100%" contentBackgroundColor="0x666666" resize="vd_resizeHandler(event)"/>
- <s:SWFLoader horizontalCenter="2" verticalCenter="2"
- id="swfLoader" source="com/bx/assets/loading1.swf" width="65" height="55" visible="{visibleFlag}"/>
- </s:Group>
热门文章推荐
- [flex]flex视频监控分区多屏播放器源代码
- [FLEX]Flex4制作Flv视频播放器
- [Flex]flex做的加载进度条loading源代码实例
- [Flex]浏览器chromeFlash安全沙箱有冲突错误的解决办法
- [Flex]as3.0检测当前摄像头状态(占用,没有,正常)三种状态
- [Flex]Flex截图功能的实现与代码实例
- [Flex]使用控件MenuBar添加一个菜单 在子菜单点击时执行事件
- [Flex]Flex数组的使用及定义方法中使用可变参数代码示例
请稍候...