Jelajahi Sumber

Downloads: update stats every 0.5s only

Felix Paul Kühne 11 tahun lalu
induk
melakukan
75f1c4535b
1 mengubah file dengan 7 tambahan dan 3 penghapusan
  1. 7 3
      AspenProject/VLCDownloadViewController.m

+ 7 - 3
AspenProject/VLCDownloadViewController.m

@@ -30,6 +30,7 @@
     VLCHTTPFileDownloader *_httpDownloader;
 
     WRRequestDownload *_FTPDownloadRequest;
+    NSTimeInterval _lastStatsUpdate;
 }
 @end
 
@@ -228,9 +229,12 @@
 
 - (void)progressUpdatedTo:(CGFloat)percentage receivedDataSize:(CGFloat)receivedDataSize  expectedDownloadSize:(CGFloat)expectedDownloadSize
 {
-    [self.progressPercent setText:[NSString stringWithFormat:@"%.1f%%", percentage*100]];
-    [self.timeDL setText:[self calculateRemainingTime:receivedDataSize expectedDownloadSize:expectedDownloadSize]];
-    [self.speedRate setText:[self calculateSpeedString:receivedDataSize]];
+    if ((_lastStatsUpdate > 0 && ([NSDate timeIntervalSinceReferenceDate] - _lastStatsUpdate > .5)) || _lastStatsUpdate <= 0) {
+        [self.progressPercent setText:[NSString stringWithFormat:@"%.1f%%", percentage*100]];
+        [self.timeDL setText:[self calculateRemainingTime:receivedDataSize expectedDownloadSize:expectedDownloadSize]];
+        [self.speedRate setText:[self calculateSpeedString:receivedDataSize]];
+            _lastStatsUpdate = [NSDate timeIntervalSinceReferenceDate];
+    }
 
     [self.progressView setProgress:percentage animated:YES];
 }