•  
  • 0
  •  
0

Adobe AIR: как можно узнать с какой скоростью качается файл?

В air-приложении качаю файл с помощью такой функции:

function download(url, filename) {
  var file        = air.File.applicationStorageDirectory.resolvePath(filename),
      request     = new air.URLRequest(url),
      stream      = new air.URLStream(),
      file_stream = new air.FileStream();

  file_stream.openAsync(file, air.FileMode.WRITE);  
  ..
  stream.addEventListener(air.ProgressEvent.PROGRESS, ProgressDownloading);  
  ..

  stream.load(request);  

  ..
  function ProgressDownloading(event)
  {
    var file_content  = new air.ByteArray(),
        bytes_loaded  = event.bytesLoaded,
        bytes_total   = event.bytesTotal,
        total_percent = Math.round(bytesLoaded * 100 / bytesTotal);

    c_log(total_precent); //Моя функция, аналог console.log firebug`а

    stream.readBytes(file_content, 0, stream.bytesAvailable);  
    file_stream.writeBytes(file_content, 0, file_content.length);  

    var progress_event = new air.ProgressEvent(air.ProgressEvent.PROGRESS);  
    progress_event.bytesLoaded = bytes_loaded;  
    progress_event.bytesTotal  = bytes_total;  
    air.NativeApplication.nativeApplication.dispatchEvent(progress_event);  
  } 
  ..
}

В функции ProgressDownloading хотелось бы помимо общего прогресса закачки получить и скорость. Каким образом это лучше сделать?

air, javascript.
спросил 921 день назад Аватор пользователя dizzy2 dizzy2
224 4
300
Чтобы написать ответ, вы должны авторизироваться.