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

flex播放器代码支持rtmp协议

时间:2012-03-31 09:14smalld_2006
flex播放器代码支持rtmp协议,flex播放器,rtmp播放器,rtmp协议

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> 

 

热门文章推荐

请稍候...

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

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