博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

AS3无缝循环播放FLV

Posted on 2013-03-11 11:37  迷梦江南  阅读(2690)  评论(0编辑  收藏  举报

 import flash.events.NetStatusEvent;
 import flash.media.Video;
 import flash.net.NetConnection;
 import flash.net.NetStream;


  private var myNc:NetConnection;
  private var client:Object;
  private var videoStream:NetStream;
  private var video:Video;
  private var videoURL:String;

 

    myNc = new NetConnection();
    myNc.connect(null);
    client = new Object();
    videoStream =new NetStream(myNc);
   
    video = new Video();
    video.width = 350;
    video.height = 200;
    video.x = 665;
    video.y = 190;
    sprite.addChild(video);
    video.attachNetStream(videoStream);
    videoStream.play(videoURL);
    videoStream.client=client;
   
    videoStream.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);

 

 private function netStatusHandler(event:NetStatusEvent):void
  { 
   switch (event.info.code) 
   {  
    case "NetConnection.Connect.Success" :   
     connectStream();   
     break;  
    case "NetStream.Play.StreamNotFound" :   
     trace("Unable to locate video: " + videoURL);   
     break;  
    case "NetStream.Buffer.Full" :   
     break;  
    case  "NetStream.Play.Stop" :
     connectStream();
     break; 
   }
  }
  
  private function connectStream():void
  {
   videoStream.pause();
   videoStream.seek(0);
   videoStream.resume();
  }