seeking not working in flex 4.5 netStream byteArray

杀马特。学长 韩版系。学妹 提交于 2019-12-24 03:40:35

问题


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


来源:https://stackoverflow.com/questions/14434579/seeking-not-working-in-flex-4-5-netstream-bytearray

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!