2010-04-19 51 views
2

當我在Flash中播放視頻時,首先開始緩衝,然後當緩衝區已滿時播放。當緩衝區正在填充時,相關的Video對象會自動顯示第一個視頻幀。針對視頻第一幀的AS3通知

有沒有辦法在此框架可用時接收通知?因爲我想隱藏視頻組件直到有圖像被顯示。

目前我處理緩衝區已滿NetStreamEvent,所以它顯示何時開始播放。但是現在我需要一個更大的緩衝區(10s),因此等待10s向用戶顯示某些內容並不好。

+1

是否有可能爲您生成第一幀(或任何海報幀),自己顯示,然後當視頻緩衝到足以播放刪除它? – heavilyinvolved 2010-04-20 02:28:20

回答

0

你應該聽「NetStream.Play.Start」;

 
package { 
    import flash.display.Sprite; 
    import flash.events.*; 
    import flash.media.Video; 
    import flash.net.NetConnection; 
    import flash.net.NetStream; 

    public class VideoExample extends Sprite { 
     private var videoURL:String = "someVideo.flv"; 
     private var connection:NetConnection; 
     private var stream:NetStream; 
     private var video:Video; 

     public function VideoExample() { 
      connection = new NetConnection(); 
      connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); 
      connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); 
      connection.connect(null); 
     } 

     private function netStatusHandler(event:NetStatusEvent):void { 

      trace("event.info.code "+event.info.code); 

      switch (event.info.code) { 
       case "NetConnection.Connect.Success": 
        connectStream(); 
        break; 

       case "NetStream.Play.Start": 
       addChild(video); 
       break; 

       case "NetStream.Play.StreamNotFound": 
        trace("Unable to locate video: " + videoURL); 
        break; 
      } 
     } 

     private function connectStream():void { 
      var stream:NetStream = new NetStream(connection); 
      stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); 
      stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); 
      video = new Video(); 
      video.attachNetStream(stream); 
      stream.play(videoURL); 

     } 

     private function securityErrorHandler(event:SecurityErrorEvent):void { 
      trace("securityErrorHandler: " + event); 
     } 

     private function asyncErrorHandler(event:AsyncErrorEvent):void { 
      // ignore AsyncErrorEvent events. 
     } 
    } 
}