1 Reply Latest reply on Jun 23, 2011 1:42 AM by fryckoort

    Latency (sync VideoElement with MovieClip)

    fryckoort

      Hi,

       

      I have a MovieClip witch contain several visuals elements, movieclip

      timeline must be sync with VideoElement.

      To do that, I start movieclip timeline when BUFFERING mediaplayer state

      is false, each 10 ms, I check if visual timeline needed to be resync

      whith mediaPlayer.currentTime (if time difference is equal or greater

      than 20 ms)

       

      The problem is : on Windows there is a latency witch affect the user

      experience, on mac it works like a charm.

       

      I use FLash CS5 and Flex SDK 4.5 + Flash Player 10.2

       

      This is my code (sample) :

       

      _videoElement = new VideoElement( null, new HTTPStreamingNetLoader());

      _parallelElement = new ParallelElement();

      _parallelElement.addChild(_videoElement);

       

      _mediaPlayer = new MediaPlayer(_parallelElement);

      _mediaPlayer.currentTimeUpdateInterval = 10;

       

      _mediaPlayer.addEventListener(TimeEvent.CURRENT_TIME_CHANGE,

      currentTimeChangeHandler);

      _mediaPlayer.addEventListener(BufferEvent.BUFFERING_CHANGE,

      bufferingChangeHandler);

       

      _mediaPlayer.play();

       

      function bufferingChangeHandler(event:BufferEvent):void

      {

      if(!event.buffering)

      {

             timeline.play();

      }

      else

      {

             timeline.pause();

      }

      }

       

      function currentTimeChangeHandler(event:TimeEvent):void

      {

             //check if timeline need to be sync

             var timelineInterval:Number = timeline.currentTime -

      _mediaPlayer.currentTime;

       

             if (Math.abs(timelineInterval) > 0.2 )

             {

                     timeline.currentTime = _mediaPlayer.currentTime;

             }

      }

       

      Timeline is ALWAYS sync. But visually we can see timeline in advance of

      the video, probably because of latency or less depending on the system.

       

      *** Sometimes I got 150 ms, sometimes 50ms. ***

       

      on Mac is always less than 30 ms

       

      If i use HTTPStreamingNetLoader NetStream.appendBytes() is used no ? so latency should be better ?

       

      What can I do to have a latency close to 0 in any environment ?

       

      Thanks !!