0

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)

Sameer H. Ibra
  • 1,816
  • 2
  • 17
  • 25

1 Answers1

0

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)

Josh
  • 8,079
  • 3
  • 24
  • 49
  • the problem of seek method is keyframe that responsible of haw the seek is accurate or not . seek will not work exactly if the video is loaded from server and the length of video is less that one-two minute duration . I test it on less than one minute duration the seek not work it will give Seek.InvalidTime Error , but when test on two minute video duration the seek will work very good not exactly the difference is +/- one second of real seek because video will search for nearest frame of KeyFrames when loaded . Thanks For replay and answer . – Sameer H. Ibra Apr 21 '13 at 06:58