flex播放器代码支持rtmp协议

 
 
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  layout="absolute" initialize="VideoExample()">   
  3. <mx:Script>   
  4. <![CDATA[   
  5.       
  6.     import flash.display.Sprite;   
  7.     import flash.events.*;   
  8.        import flash.media.Video;   
  9.        import flash.net.NetConnection;   
  10.        import flash.net.NetStream;   
  11.       
  12.     private var videoURL:String = "IronMan.flv";   
  13.           private var connection:NetConnection;   
  14.           private var stream:NetStream;   
  15.             
  16.          public function VideoExample():void {   
  17.             connection = new NetConnection();   
  18.             connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);   
  19.             connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR,  securityErrorHandler);   
  20.             connection.connect("rtmp://localhost/oflaDemo");   
  21.          }   
  22.            
  23.          private function netStatusHandler(event:NetStatusEvent):void {   
  24.               switch (event.info.code) {   
  25.                   case "NetConnection.Connect.Success":   
  26.                       connectStream();   
  27.                       break;   
  28.                   case "NetStream.Play.StreamNotFound":   
  29.                       trace("Unable to locate video: " + videoURL);   
  30.                       break;   
  31.               }   
  32.           }   
  33.      
  34.     private function connectStream():void {   
  35.               var stream:NetStream = new NetStream(connection);   
  36.               stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);   
  37.               stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);   
  38.               var video:Video = new Video();   
  39.               video.width = 400;   
  40.               video.height = 400;   
  41.               video.attachNetStream(stream);   
  42.               stream.play(videoURL);   
  43.               sprct.addChild(video);   
  44.           }   
  45.             
  46.           private function securityErrorHandler(event:SecurityErrorEvent):void {   
  47.               trace("securityErrorHandler: " + event);   
  48.           }   
  49.             
  50.           private function asyncErrorHandler(event:AsyncErrorEvent):void {   
  51.               // ignore AsyncErrorEvent events.   
  52.           }   
  53. ]]>   
  54. </mx:Script>   
  55. <mx:VideoDisplay id="sprct" x="57" y="22" width="707" height="494"/>   
  56. </mx:Application>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值