Marino Faggiana 1 year ago
parent
commit
75a943e09f

+ 2 - 1
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift

@@ -44,6 +44,8 @@ class NCPlayer: NSObject {
 
     weak var imageVideoContainer: imageVideoContainerView?
 
+    internal var counterSeconds: Double = 0
+
     // MARK: - View Life Cycle
 
     init(imageVideoContainer: imageVideoContainerView, playerToolBar: NCPlayerToolBar?, metadata: tableMetadata, viewerMediaPage: NCViewerMediaPage?) {
@@ -212,7 +214,6 @@ extension NCPlayer: VLCMediaPlayerDelegate {
             print("Played mode: ENDED")
             break
         case .error:
-            playerToolBar?.disableAllControl()
             let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_error_something_wrong_")
             NCContentPresenter.shared.showError(error: error, priority: .max)
             print("Played mode: ERROR")

+ 10 - 40
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift

@@ -51,16 +51,6 @@ class NCPlayerToolBar: UIView {
     private var ncplayer: NCPlayer?
     private var metadata: tableMetadata?
     private var wasInPlay: Bool = false
-    private var timerAutoHide: Timer?
-    private var timerAutoHideSeconds: Double {
-        get {
-            if NCUtility.shared.isSimulator() { // for test
-                return 3
-            } else {
-                return 5
-            }
-        }
-    }
 
     // MARK: - View Life Cycle
 
@@ -99,6 +89,10 @@ class NCPlayerToolBar: UIView {
         backButton.setImage(NCUtility.shared.loadImage(named: "gobackward.10", color: .white), for: .normal)
 
         forwardButton.setImage(NCUtility.shared.loadImage(named: "goforward.10", color: .white), for: .normal)
+
+        // Normally hide
+        self.alpha = 0
+        self.isHidden = true
     }
 
     required init?(coder aDecoder: NSCoder) {
@@ -106,7 +100,6 @@ class NCPlayerToolBar: UIView {
     }
 
     deinit {
-        timerAutoHide?.invalidate()
         print("deinit NCPlayerToolBar")
     }
 
@@ -134,7 +127,11 @@ class NCPlayerToolBar: UIView {
             muteButton.setImage(NCUtility.shared.loadImage(named: "audioOn", color: .white), for: .normal)
         }
 
-        show()
+        if viewerMediaScreenMode == .normal {
+            show()
+        } else {
+            hide()
+        }
     }
 
     public func update() {
@@ -155,23 +152,10 @@ class NCPlayerToolBar: UIView {
         MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyElapsedPlaybackTime] = positionInSecond
     }
 
-    public func disableAllControl() {
-
-        muteButton.isEnabled = false
-        playButton.isEnabled = false
-        forwardButton.isEnabled = false
-        backButton.isEnabled = false
-        playbackSlider.isEnabled = false
-    }
-
     // MARK: -
 
     public func show() {
 
-        if let ncplayer = ncplayer, ncplayer.isPlay() {
-            startTimerAutoHide()
-        }
-
         UIView.animate(withDuration: 0.3, animations: {
             self.alpha = 1
         }, completion: { (_: Bool) in
@@ -179,13 +163,7 @@ class NCPlayerToolBar: UIView {
         })
     }
 
-    private func startTimerAutoHide() {
-
-        timerAutoHide?.invalidate()
-        timerAutoHide = Timer.scheduledTimer(timeInterval: timerAutoHideSeconds, target: self, selector: #selector(hide), userInfo: nil, repeats: false)
-    }
-
-    @objc func hide() {
+    func hide() {
 
         UIView.animate(withDuration: 0.3, animations: {
             self.alpha = 0
@@ -230,8 +208,6 @@ class NCPlayerToolBar: UIView {
         default:
             break
         }
-
-        startTimerAutoHide()
     }
 
     // MARK: - Action
@@ -245,10 +221,8 @@ class NCPlayerToolBar: UIView {
 
         if ncplayer.isPlay() {
             ncplayer.playerPause()
-            timerAutoHide?.invalidate()
         } else {
             ncplayer.playerPlay()
-            startTimerAutoHide()
         }
     }
 
@@ -265,8 +239,6 @@ class NCPlayerToolBar: UIView {
             ncplayer.setVolumeAudio(100)
             muteButton.setImage(NCUtility.shared.loadImage(named: "audioOn", color: .white), for: .normal)
         }
-
-        startTimerAutoHide()
     }
 
     @IBAction func tapForward(_ sender: Any) {
@@ -274,7 +246,6 @@ class NCPlayerToolBar: UIView {
         guard let ncplayer = ncplayer else { return }
 
         ncplayer.jumpForward(10)
-        startTimerAutoHide()
     }
 
     @IBAction func tapBack(_ sender: Any) {
@@ -282,6 +253,5 @@ class NCPlayerToolBar: UIView {
         guard let ncplayer = ncplayer else { return }
 
         ncplayer.jumpBackward(10)
-        startTimerAutoHide()
     }
 }

+ 6 - 2
iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift

@@ -141,7 +141,7 @@ class NCViewerMedia: UIViewController {
             }
         }
 
-        if viewerMediaPage?.screenMode == .normal {
+        if viewerMediaScreenMode == .normal {
 
             viewerMediaPage?.navigationController?.setNavigationBarHidden(false, animated: true)
 
@@ -178,7 +178,11 @@ class NCViewerMedia: UIViewController {
                         }
                     }
                 } else {
-                    playerToolBar?.show()
+                    if viewerMediaScreenMode == .normal {
+                        playerToolBar?.show()
+                    } else {
+                        playerToolBar?.hide()
+                    }
                 }
             }
             

+ 17 - 9
iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.swift

@@ -27,15 +27,15 @@ import MediaPlayer
 import JGProgressHUD
 import Alamofire
 
+enum ScreenMode {
+    case full, normal
+}
+var viewerMediaScreenMode: ScreenMode = .normal
+
 class NCViewerMediaPage: UIViewController {
 
     @IBOutlet weak var progressView: UIProgressView!
 
-    enum ScreenMode {
-        case full, normal
-    }
-    var screenMode: ScreenMode = .normal
-
     var pageViewController: UIPageViewController {
         return self.children[0] as! UIPageViewController
     }
@@ -134,7 +134,7 @@ class NCViewerMediaPage: UIViewController {
 
     override var preferredStatusBarStyle: UIStatusBarStyle {
 
-        if screenMode == .normal {
+        if viewerMediaScreenMode == .normal {
             return .default
         } else {
             return .lightContent
@@ -142,7 +142,7 @@ class NCViewerMediaPage: UIViewController {
     }
 
     override var prefersHomeIndicatorAutoHidden: Bool {
-        return screenMode == .full
+        return viewerMediaScreenMode == .full
     }
 
     override var prefersStatusBarHidden: Bool {
@@ -182,6 +182,10 @@ class NCViewerMediaPage: UIViewController {
             hideStatusBar = false
             progressView.isHidden = false
 
+            if metadatas[currentIndex].classFile == NKCommon.TypeClassFile.video.rawValue || metadatas[currentIndex].classFile == NKCommon.TypeClassFile.audio.rawValue {
+                currentViewController.playerToolBar?.show()
+            }
+
             NCUtility.shared.colorNavigationController(navigationController, backgroundColor: .systemBackground, titleColor: .label, tintColor: nil, withoutShadow: false)
             view.backgroundColor = .systemBackground
             textColor = .label
@@ -192,11 +196,15 @@ class NCViewerMediaPage: UIViewController {
             hideStatusBar = true
             progressView.isHidden = true
 
+            if metadatas[currentIndex].classFile == NKCommon.TypeClassFile.video.rawValue || metadatas[currentIndex].classFile == NKCommon.TypeClassFile.audio.rawValue {
+                currentViewController.playerToolBar?.hide()
+            }
+
             view.backgroundColor = .black
             textColor = .white
         }
 
-        screenMode = mode
+        viewerMediaScreenMode = mode
 
         setNeedsStatusBarAppearanceUpdate()
         setNeedsUpdateOfHomeIndicatorAutoHidden()
@@ -556,7 +564,7 @@ extension NCViewerMediaPage: UIGestureRecognizerDelegate {
 
     @objc func didSingleTapWith(gestureRecognizer: UITapGestureRecognizer) {
 
-        if screenMode == .full {
+        if viewerMediaScreenMode == .full {
             changeScreenMode(mode: .normal, toggleToolbar: true)
         } else {
             changeScreenMode(mode: .full, toggleToolbar: true)