marinofaggiana 3 年之前
父节点
当前提交
6e345f0285

+ 9 - 3
iOSClient/Viewer/NCViewerImage/NCViewerImage.swift

@@ -521,7 +521,7 @@ extension NCViewerImage: UIGestureRecognizerDelegate {
                 self.currentViewerImageZoom?.centreConstraints()
                 // VideoToolBar
                 if self.currentMetadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue || self.currentMetadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue {
-                    self.viewerVideo?.viewerVideoToolBar?.isHidden = false
+                    self.viewerVideo?.viewerVideoToolBar?.showToolBar()
                 }
             }
             return
@@ -550,6 +550,12 @@ extension NCViewerImage: UIGestureRecognizerDelegate {
         }
         */
         
+        if currentMetadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue || currentMetadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue {
+            let wasHidden = viewerVideo?.viewerVideoToolBar?.isHidden
+            viewerVideo?.viewerVideoToolBar?.showToolBar()
+            if wasHidden ?? false { return }
+        }
+        
         if currentMode == .full {
             
             navigationController?.setNavigationBarHidden(false, animated: false)
@@ -588,14 +594,14 @@ extension NCViewerImage: NCViewerImageZoomDelegate {
         navigationItem.title = metadata.fileNameView
         currentMetadata = metadata
         currentViewerImageZoom = viewerImageZoom
-        viewerImageZoom.videoToolBar.isHidden = true
+        viewerImageZoom.videoToolBar.hideToolBar()
         viewerVideo = NCViewerVideo.init(view: viewerImageZoom.imageView, viewerVideoToolBar: viewerImageZoom.videoToolBar)
         
         if (currentMetadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue || currentMetadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue) {
             DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
                 self.viewerVideo?.videoPlay(metadata: metadata)
             }
-            viewerImageZoom.videoToolBar.isHidden = false
+            viewerImageZoom.videoToolBar.showToolBar()
         }
             
         if !NCOperationQueue.shared.downloadExists(metadata: metadata) {

+ 6 - 9
iOSClient/Viewer/NCViewerImage/NCViewerImageZoom.swift

@@ -152,11 +152,6 @@ class NCViewerImageZoom: UIViewController {
         
         updateZoomScale()
         centreConstraints()
-        
-        // VideoToolBar
-        if metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue {
-            self.videoToolBar.isHidden = false
-        }
     }
     
     //MARK: - Gesture
@@ -166,7 +161,9 @@ class NCViewerImageZoom: UIViewController {
         if detailView.isShow() { return }
         
         // NO ZOOM for Audio / Video
-        if metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue { return }
+        if (metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue) && !videoToolBar.isHidden {
+            return
+        }
         
         let pointInView = gestureRecognizer.location(in: imageView)
         var newZoomScale = scrollView.maximumZoomScale
@@ -205,7 +202,7 @@ class NCViewerImageZoom: UIViewController {
             startImageViewBottomConstraint = imageViewBottomConstraint.constant
              
             // VideoToolBar
-            self.videoToolBar.isHidden = true
+            self.videoToolBar.hideToolBar()
             
         case .ended:
             
@@ -229,10 +226,10 @@ class NCViewerImageZoom: UIViewController {
             // VideoToolBar
             if metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue {
                 if detailView.isShow() {
-                    self.videoToolBar.isHidden = true
+                    self.videoToolBar.hideToolBar()
                 } else {
                     DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
-                        self.videoToolBar.isHidden = false
+                        self.videoToolBar.showToolBar()
                     }
                 }
             }

+ 30 - 8
iOSClient/Viewer/NCViewerVideo/NCViewerVideoToolBar.swift

@@ -34,8 +34,9 @@ class NCViewerVideoToolBar: UIView {
     @IBOutlet weak var labelCurrentTime: UILabel!
     
     var player: AVPlayer?
-    fileprivate let seekDuration: Float64 = 15
-    
+    private let seekDuration: Float64 = 15
+    private var timerAutoHide: Timer?
+
     override func willMove(toWindow newWindow: UIWindow?) {
         super.willMove(toWindow: newWindow)
 
@@ -94,16 +95,26 @@ class NCViewerVideoToolBar: UIView {
         player?.addPeriodicTimeObserver(forInterval: CMTimeMakeWithSeconds(1, preferredTimescale: 1), queue: .main, using: { (CMTime) in
             
             if self.player?.currentItem?.status == .readyToPlay {
-                let currentSeconds: Float64 = CMTimeGetSeconds(self.player!.currentTime())
-                self.playbackSlider.value = Float(currentSeconds)
-                self.labelCurrentTime.text = self.stringFromTimeInterval(interval: currentSeconds)
-                self.labelOverallDuration.text = "-" + self.stringFromTimeInterval(interval: durationSeconds - currentSeconds)
+                if self.isHidden == false {
+                    self.updateOutlet()
+                }
             }
         })
         
         setToolBar()
     }
     
+    @objc public func hideToolBar() {
+        self.isHidden = true
+    }
+    
+    @objc public func showToolBar() {
+        updateOutlet()
+        self.isHidden = false
+        timerAutoHide?.invalidate()
+        timerAutoHide = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(hideToolBar), userInfo: nil, repeats: true)
+    }
+    
     public func setToolBar() {
 
         if player?.rate == 1 {
@@ -118,6 +129,19 @@ class NCViewerVideoToolBar: UIView {
             muteButton.setImage(NCUtility.shared.loadImage(named: "audioOn", color: .white), for: .normal)
         }
     }
+    
+    private func updateOutlet() {
+        
+        if let duration = player?.currentItem?.asset.duration, let currentTime = player?.currentTime() {
+            
+            let durationSeconds: Float64 = CMTimeGetSeconds(duration)
+            let currentSeconds: Float64 = CMTimeGetSeconds(currentTime)
+            
+            self.playbackSlider.value = Float(currentSeconds)
+            self.labelCurrentTime.text = self.stringFromTimeInterval(interval: currentSeconds)
+            self.labelOverallDuration.text = "-" + self.stringFromTimeInterval(interval: durationSeconds - currentSeconds)
+        }
+    }
 
     //MARK: - Action
     
@@ -171,8 +195,6 @@ class NCViewerVideoToolBar: UIView {
     
     //MARK: - Algorithms
     
-    
-    
     func stringFromTimeInterval(interval: TimeInterval) -> String {
     
         let interval = Int(interval)