質問

i try to do seek function in NetStream class using Action Script language , The seek is not work correctly . I read about KeyFrames in NetStream , what is the relationship between KeyFrames and seek ? is there other problem of using seek function by NetStream ? onClick() Function to Seek;

  private function onClick(event:MouseEvent):void
    {
         if (event.currentTarget is Group)
         {
             var myGroup:Group = event.currentTarget as Group;
             if ( myGroup.mouseX >= 100)
              {
                 mouseClickedXPos = myGroup.mouseX;
                 ns.inBufferSeek = true;
                 var seekTime:Number = (mouseClickedXPos-100) * (totalTime/(controlBarControls.width-100));
                 ns.seek(seekTime);     
             }  
         }
    }

there is event for netStatus for net stream

ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

private function onNetStatus(event:NetStatusEvent):void
    {
        if ( event.info == "NetStream.Play.StreamNotFound" )
            legend.text = "Video file passed, not available!";
        else if(event.info.code == "NetStream.Play.FileStructureInvalid")
            legend.text = "Video file passed, FileStructureInvalid";
    }

event.info.code is be NetStream.Seek.InvalidTime , the video will stop playing , sometime will seek for end of video , but i trace it , the ns.time() doesn't update to new value (seekTime)

役に立ちましたか?

解決

I'm not entirely sure, but I think you got this line wrong:

var seekTime:Number = (mouseClickedXPos-100) * (totalTime/(controlBarControls.width-100));

Try this instead:

var seekTime:Number = ( ( mouseClickedXPos - 100 ) / ( controlBarControls.width - 100 ) ) * totalTime;

Basically, you were comparing two completely different quantities to form a ratio and multiply that by the mouse click position. Instead, divide that mouseX by the total width (giving the position of the click as a percentage of the total width) and multiply that by the time (giving you a percentage of the total time).

I'm not overly familiar with the way NetStream works (I've used it, just not extensively enough to know this off the top of my head), but if you pass a time greater than the totalTime, there has to be an error or it has to handle it by either not completing the command or by setting the value to 0 (which I personally think is what would happen. It's how I would do it, at any rate)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top