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

[Flex]Flex和Red5制作视频直播播放器

时间:2012-07-11 14:25JavaChenYang
[Flex]Flex和Red5制作视频直播播放器,视频直播,Red5视频直播

客户端使用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>   

热门文章推荐

请稍候...

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

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