但是,您的代碼應該可以正常工作,appendBytes方法包含在Flash Player 10.1和更高版本中。如果你正在編譯低於10.1的任何東西,你會得到類似於你的問題中列出的錯誤。在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);
}
}
}
祝你好運!
這種技術可以用於格式爲aac/m4a的音頻文件嗎? –
如果您正在將一個持久黑幀編碼爲flv,則可以使用此技術將http流aac/m4a。我的測試flv編碼H264和aac/mp4a。查看這個鏈接瞭解更多關於http psudostreaming的信息。 http://www.longtailvideo.com/support/jw-player/jw-player-for-flash-v5/12534/video-delivery-http-pseudo-streaming – stat