0 Replies Latest reply on Apr 17, 2009 2:18 PM by firdosh

    Estimating time to download a file (FLV / MP3)

    firdosh Level 1

      I am trying to estimate how it would take for a user to download a mp3 /flv file.

       

       

      private function init():void
      {
                     _netStream = new NetStream(_netConnection);
                    
                      _netStream.play(test.flv");
                      _netStream.client = _metaDataObj;
                      bandwidth = new Timer(3000,1);
                      bandwidth .addEventListener(TimerEvent.TIMER , onCalculateBandwidth, false , 0 , true);
                      bandwidth .start();
      
                      checkVideoProgress = new Timer(100,0);
                      checkVideoProgress.addEventListener(TimerEvent.TIMER , onVideoProgressHandler , false , 0 , true);
                      checkVideoProgress.start();
      
                     _startTime=getTimer();
      }
      
      
      private function onVideoProgressHandler(e:TimerEvent):void
       {              
                      if (_netStream.bytesLoaded == _netStream.bytesTotal)
                      {
                          trace("Actual Download Time = " + Math.ceil((getTimer() - _startTime)/1000));             
                          checkVideoProgress.stop();                   
                      } 
       }
      
      
      private function onCalculateBandwidth(e:TimerEvent):void
       {
      
          var timeToDownloadFile:Number= Math.ceil((3 * _netStream.bytesTotal) / _netStream.bytesLoaded);
      }
      

       

      So basically check the bytesLoaded in 3 seconds  and then try to estimate how long it would take to download bytesTotal but for some reason the numbers are way off

       

      24 sec when actual download time is 10 sec

      330 sec when actual download time is 26sec

       


      Thanks,

      Firdosh