2011-11-27 12 views

回答

1

只要flv正在流式傳輸,您將需要使用NetStream.appendBytesAction和NetStream.appendBytes進行http流式播放。結帳在ByteArray.org以下博客文章,也低於簡單的例子:

AppendBytes


播放初始化:

var video:Video = new Video(width, height); 
var video_nc:NetConnection = new NetConnection(); 
var video_ns:NetStream = new NetStream(); 

video_nc.connect(null); 
video_ns.play(null); 
video_ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN); 

video.attachNetStream(video_ns); 

使用ProgressEvent.PROGRESS處理程序:

video_ns.appendBytes(bytesAvailable); 

這實質上就是它的jist,bytesAvailable將代表重新發送來自事件數據緩衝區的讀取字節。一個完整的例子如下:

package 
{ 

import flash.display.Sprite; 
import flash.events.NetStatusEvent; 
import flash.events.ProgressEvent; 
import flash.media.Video; 
import flash.net.NetConnection; 
import flash.net.NetStream; 
import flash.net.NetStreamAppendBytesAction; 
import flash.net.URLRequest; 
import flash.net.URLStream; 
import flash.utils.ByteArray; 

[SWF(width="1280", height="720")] 
public class NetStreamAppendBytes extends Sprite 
{ 

    var video:Video; 
    var video_nc:NetConnection; 
    var video_ns:NetStream; 

    var video_stream:URLStream; 

    public function NetStreamAppendBytes() 
    { 
     super(); 

     video_nc = new NetConnection(); 
     video_nc.connect(null); 

     video_ns = new NetStream(video_nc); 
     video_ns.client = this; 
     video_ns.addEventListener(NetStatusEvent.NET_STATUS, ns_statusHandler); 

     video = new Video(1280, 720); 
     video.attachNetStream(video_ns); 
     video.smoothing = true; 

     video_ns.play(null); 
     video_ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN); 

     video_stream = new URLStream(); 
     video_stream.addEventListener(ProgressEvent.PROGRESS, videoStream_progressHandler); 

     video_stream.load(new URLRequest("path_to_flv")); 

     addChild(video); 
    } 

    private function ns_statusHandler(event:NetStatusEvent):void 
    { 
     trace(event.info.code); 
    } 

    private function videoStream_progressHandler(event:ProgressEvent):void 
    { 
     var bytes:ByteArray = new ByteArray(); 

     video_stream.readBytes(bytes); 
     video_ns.appendBytes(bytes); 
    } 

} 

} 

祝你好運!

相關問題