marinofaggiana 4 lat temu
rodzic
commit
e81e12ef84
1 zmienionych plików z 15 dodań i 13 usunięć
  1. 15 13
      iOSClient/Viewer/NCViewerImage/NCViewerImage.swift

+ 15 - 13
iOSClient/Viewer/NCViewerImage/NCViewerImage.swift

@@ -351,7 +351,9 @@ class NCViewerImage: UIViewController {
     //MARK: - Video
     
     func videoPlay(metadata: tableMetadata) {
-                                
+                
+        let widthProgressView = Double(self.progressView.bounds.width)
+        
         NCKTVHTTPCache.shared.startProxy(user: appDelegate.user, password: appDelegate.password, metadata: metadata)
 
         if let url = NCKTVHTTPCache.shared.getVideoURL(metadata: metadata) {
@@ -367,18 +369,18 @@ class NCViewerImage: UIViewController {
                 
                 currentViewerImageZoom!.imageView.layer.addSublayer(videoLayer!)
                 
-                var interval:Double = 0.1
-                if let duration = player?.currentItem?.asset.duration {
-                    let durationSeconds = Double(CMTimeGetSeconds(duration))
-                    let width = Double(progressView.bounds.width)
-                    interval = (0.5 * durationSeconds) / width
-                }
-                
-                let time = CMTime(seconds: interval, preferredTimescale: CMTimeScale(NSEC_PER_SEC))
-                if CMTIME_IS_VALID(time) {
-                    timeObserver = player?.addPeriodicTimeObserver(forInterval: time, queue: .main, using: { [weak self] time in
-                        self?.updateVideoProgressBar(time: time)
-                    })
+                DispatchQueue.global().async {
+                    if let duration = self.player?.currentItem?.asset.duration {
+                        let durationSeconds = Double(CMTimeGetSeconds(duration))
+                        let interval = (0.5 * durationSeconds) / widthProgressView
+                        
+                        let time = CMTime(seconds: interval, preferredTimescale: CMTimeScale(NSEC_PER_SEC))
+                        if CMTIME_IS_VALID(time) {
+                            self.timeObserver = self.player?.addPeriodicTimeObserver(forInterval: time, queue: .main, using: { [weak self] time in
+                                self?.updateVideoProgressBar(time: time)
+                            })
+                        }
+                    }
                 }
                 
                 // At end go back to start