开发者

Do you know if there's any problem with netstream.appendBytes() for streaming?

I use netstream.appendBytes to get the streaming (flv) from http, but works intermittently (it works, after refresh, doesn't work, then it works and so on...)

What is the problem?, I have not idea

My code is:

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();


Maybe use a stream buffer as HTTP is TCP so not all packets arrive at time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜