seeking not working in flex 4.5 netStream byteArra

2019-07-18 03:17发布

问题:

I am trying to play a flv video file in flex 4.5 with netStream byteArray. What I am doing is below:

  1. Creating a netStream and video object
  2. Attaching a netStream with video
  3. Reading flv file in byteArray
  4. Append byteArray in netStream using "appendBytes" method
  5. Playing video

In this scenario Play, Pause, Stop functionalities are working fine with video.

But when I am trying to seeking in video then it is not working.

You can follow the code what I am doing by clicking on the link http://pastebin.com/fZp0mKDs

Can anybody tell me, where am I am going wrong to implement seeking.

Any code sample or any kind of help would be appreciated.

回答1:

I got, the code below worked in my case

// onmetadata function get all timestamp and corresponding fileposition..
function onMetaData(informationObject:Object):void 
{
    for (var propertyName:String in informationObject) 
    {
        if (propertyName == "keyframes")
        {
            var kfObject:Object = informationObject[propertyName];
            var timeArray:Array = kfObject["times"];
            var filePositionArray:Array = kfObject["filepositions"];

            for(var i:int=0;i<timeArray.length;i++)
            {
                var tagPosition:int = filePositionArray[i];//Read the tag size;
                var timestamp:Number = timeArray[i];//read the timestamp;
                tags.push({timestamp:timestamp,tagPosition:tagPosition});
            }
        }
    }
}

// onseek click get approximate timestamp and its fileposition
protected function seek_click(seektime:Number):void
{
    var currentTime:Number = 0;
    var previousTime:Number = 0;

    for (var i:int=1; i<tags.length; i++)
    {
        currentTime = tags[i].timestamp;
        previousTime = tags[i-1].timestamp;

        if(previousTime < seektime)
        {
            if(seektime < currentTime)
            {
                seekPos = tags[i-1].tagPosition;
                stream.seek(previousTime);
                break;
            }
        }
    }
}


// append bytes on seekposition
private function netStatusHandler(event:NetStatusEvent):void 
{
    switch (event.info.code) 
    {
        case "NetStream.Seek.Notify" :

        stream.appendBytesAction(NetStreamAppendBytesAction.RESET_SEEK);
        totalfilePositionArray.position = seekPos;

        var bytes:filePositionArray = new filePositionArray();

        totalfilePositionArray.readBytes(bytes);
        stream.appendBytes(bytes);

        stream.resume();

        break;
    }
}

For inject MetaData keyframes into flv file.Use some injector tool, fe. FLV MetaData Injector

http://www.buraks.com/flvmdi/



回答2:

I think there is a problem in seeking of byteArray constructed after reading file. Just play you netStream directly, it works:

var fileName:String = "dummy-video.flv";
ns.play(fileName);