·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[RED5]运用Flex与Red5实现视频直播源代码

时间:2014-07-14 21:26酷播
服务器端可以空实现ApplicationAdapter:示例如下,客户端使用Flex实现摄像头获取视频并发布代码如下

1,服务器端可以空实现ApplicationAdapter:示例如下:

  1. package org.chy.flex01; 
  2. import org.red5.server.adapter.ApplicationAdapter; 
  3. public class Application extends ApplicationAdapter{ 
  4.  

客户端使用Flex实现摄像头获取视频并发布代码如下:

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()"> 
  3.     <mx:Script> 
  4.         <!--[CDATA[ 
  5.             import flash.net.NetConnection; 
  6.             import flash.net.NetStream; 
  7.             import flash.events.NetStatusEvent; 
  8.             import mx.controls.Alert; 
  9.              
  10.             private var nc:NetConnection; 
  11.             private var ns:NetStream; 
  12.             private var cam:Camera; 
  13.              
  14.             private function init():void{ 
  15.                 nc = new NetConnection(); 
  16.                 nc.addEventListener(NetStatusEvent.NET_STATUS,connectServerHander); 
  17.                 nc.client  = this
  18.                 nc.connect("rtmp://58.116.56.68:1935/Flex01"); 
  19.             } 
  20.              
  21.             private function connectServerHander(evt:NetStatusEvent):void{ 
  22.                 trace(evt.info.code);  
  23.                 cam = Camera.getCamera(); 
  24.                  
  25.                 if(cam != null){ 
  26.                     cam.setMode(313,194,30); 
  27.                     cam.setQuality(0,70); 
  28.                     ns = new NetStream(nc);  
  29.                     ns.attachCamera(cam); 
  30.                     ns.publish("red5"); 
  31.                      
  32.                     var vi:Video = new Video(); 
  33.                     vi.width = 313
  34.                     vi.height = 194
  35.                     vi.attachCamera(cam); 
  36.                     videoDisplay.addChild(vi); 
  37.                      
  38.                 }else{ 
  39.                     Alert.show("no Camera"); 
  40.                 } 
  41.             } 
  42.                          
  43.             public function onBWDone():void{ 
  44.              
  45.             } 
  46.              
  47.         ]]--> 
  48.     </mx:Script> 
  49.      
  50.     <mx:VideoDisplay x="162" y="77" width="313" height="194" id="videoDisplay"/> 
  51.      
  52. </mx:Application> 

客户端使用Flex play视频代码如下:

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()"> 
  3.  
  4.     <mx:Script> 
  5.         <!--[CDATA[ 
  6.              
  7.             import flash.display.*; 
  8.             import flash.utils.*; 
  9.             import flash.events.*; 
  10.             import flash.net.*; 
  11.             import flash.media.Video; 
  12.             import flash.media.Camera; 
  13.              
  14.             private var nc:NetConnection; 
  15.              
  16.             private function init():void{ 
  17.                 nc = new NetConnection(); 
  18.                 nc.connect("rtmp://58.116.56.68:1935/Flex01"); 
  19.                 nc.addEventListener(NetStatusEvent.NET_STATUS,connectHandler); 
  20.             } 
  21.  
  22.             private function connectHandler(evt:NetStatusEvent):void{ 
  23.                  
  24.                 var ns:NetStream = new NetStream(nc); 
  25.                 var video:Video=new Video() ; 
  26.                 video.width = 313
  27.                 video.height = 194
  28.                 video.attachNetStream(ns); 
  29.                 ns.play("red5"); 
  30.                 videoDisplay.addChild(video); 
  31.                  
  32.             } 
  33.              
  34.         ]]--> 
  35.     </mx:Script> 
  36.      
  37.     <mx:Panel x="132" y="78" width="356" height="266" layout="absolute" title="CuPlayer现场直播" fontSize="14"> 
  38.         <mx:VideoDisplay x="10" y="10" width="320" height="193" id="videoDisplay"/> 
  39.     </mx:Panel> 
  40.      
  41. </mx:Application> 

 

热门文章推荐

请稍候...

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

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