2010-12-21 60 views
0

我用netstream.appendBytes擺脫HTTP流(FLV),但間歇工作(它的工作原理,刷新後不工作,那麼它的工作原理等等...)你知道netstream.appendBytes()是否有問題嗎?

問題是什麼?我沒有想法

我的代碼是:

import flash.display.*; 
import flash.events.* 
import flash.net.*; 

import flash.utils.ByteArray; 
import com.hurlant.util.Hex; 

var videoURL:String = "http://url/vivo/flash"; 

//elemento de conexíon 
var conn:NetConnection = new NetConnection(); 
conn.connect(null); 
//stream de red 
var stream:NetStream; 
//conexión 
stream = new NetStream(conn); 
//oyente 
stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); 



function Play() 
{ 
    var urlStream:URLStream = new URLStream(); 
    //oyentes de URLStream 
    urlStream.addEventListener(StatusEvent.STATUS, inStatus); 
    urlStream.addEventListener(Event.COMPLETE, completeHandler); 
    urlStream.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);  

    urlStream.addEventListener(ProgressEvent.PROGRESS, oyenteProcesoCarga); 
    //urlStream.addEventListener(ProgressEvent.PROGRESS, describeProcesoCarga); 

    urlStream.addEventListener(IOErrorEvent.IO_ERROR, ioError); 
    //Video 
    var video:Video = new Video(640,480); 
    video.attachNetStream(stream); 
    addChild(video); 

    stream.play(null); 

    urlStream.load(new URLRequest(videoURL)); 
} 

function ioError(event:IOErrorEvent):void 
{ 
    textArea.text += event + "\n"; 
} 

function oyenteProcesoCarga(event:ProgressEvent):void 
{ 
    var encr:ByteArray = new ByteArray(); 
     event.target.readBytes(encr); 
     stream.appendBytes(encr); 
} 

function describeProcesoCarga(event:ProgressEvent):void 
{ 
    if (event.target.bytesAvailable > 0){ 
     var encr:ByteArray = new ByteArray(); 
     event.target.readBytes(encr); 
    } 
} 


function securityErrorHandler(event:SecurityErrorEvent):void { 
} 

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

function inStatus(event:StatusEvent):void { 
} 

Play(); 
+0

爲什麼不使用`NetStream.play(url)`? – www0z0k 2010-12-21 16:26:38

回答

1

也許使用流緩衝區HTTP是TCP所以不是所有的數據包到達的時間到達。