marinofaggiana 3 年之前
父節點
當前提交
1390824621

+ 13 - 3
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift

@@ -73,7 +73,7 @@ class NCPlayer: NSObject {
             if let item = notification.object as? AVPlayerItem, let currentItem = self.appDelegate.player?.currentItem, item == currentItem {
                 self.videoSeek(time: .zero)
                 if !(detailView?.isShow() ?? false) {
-                    self.playerToolBar?.show(enableTimerAutoHide: false)
+                    NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShowPlayerToolBar, userInfo: ["ocId":metadata.ocId, "enableTimerAutoHide": false])
                 }
                 NCKTVHTTPCache.shared.saveCache(metadata: metadata)
             }
@@ -112,7 +112,7 @@ class NCPlayer: NSObject {
                         self.playerToolBar?.setBarPlayer(ncplayer: self, timeSeek: timeSeek, metadata: metadata)
                         self.generatorImagePreview()
                         if !(detailView?.isShow() ?? false) {
-                            self.playerToolBar?.show(enableTimerAutoHide: false)
+                            NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShowPlayerToolBar, userInfo: ["ocId":metadata.ocId, "enableTimerAutoHide": false])
                         }
                     }
                     break
@@ -169,6 +169,15 @@ class NCPlayer: NSObject {
         if appDelegate.player?.rate == 1 { return true } else { return false }
     }
     
+    func isPictureInPictureActive() -> Bool {
+        
+        if let pictureInPictureController = pictureInPictureController, pictureInPictureController.isPictureInPictureActive {
+            return true
+        } else {
+            return false
+        }
+    }
+    
     func playerPlay() {
                 
         appDelegate.player?.play()
@@ -270,9 +279,10 @@ extension NCPlayer: AVPictureInPictureControllerDelegate {
     }
     
     func pictureInPictureControllerDidStopPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) {
+        guard let metadata = self.metadata else { return }
 
         if !isPlay() {
-            playerToolBar?.show(enableTimerAutoHide: false)
+            NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShowPlayerToolBar, userInfo: ["ocId":metadata.ocId, "enableTimerAutoHide": false])
         }
     }
 }

+ 13 - 3
iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift

@@ -110,6 +110,7 @@ class NCViewerMedia: UIViewController {
         NotificationCenter.default.addObserver(self, selector: #selector(downloadedThumbnail(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadedThumbnail), object: nil)
         
         NotificationCenter.default.addObserver(self, selector: #selector(hidePlayerToolBar(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterHidePlayerToolBar), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(showPlayerToolBar(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterShowPlayerToolBar), object: nil)
     }
     
     override func viewWillDisappear(_ animated: Bool) {
@@ -156,7 +157,7 @@ class NCViewerMedia: UIViewController {
         print("deinit NCViewerMedia")        
     }
     
-    func changeScreenMode(mode: ScreenMode) {
+    func changeScreenMode(mode: ScreenMode, enableTimerAutoHide: Bool = false) {
         
         if mode == .normal {
             
@@ -164,7 +165,7 @@ class NCViewerMedia: UIViewController {
             progressView.isHidden = false
 
             if !currentViewController.detailView.isShow() {
-                currentViewController.playerToolBar.show(enableTimerAutoHide: true)
+                currentViewController.playerToolBar.show(enableTimerAutoHide: enableTimerAutoHide)
             }
             
             NCUtility.shared.colorNavigationController(navigationController, backgroundColor: NCBrandColor.shared.systemBackground, titleColor: NCBrandColor.shared.label, tintColor: nil, withoutShadow: false)
@@ -303,6 +304,15 @@ class NCViewerMedia: UIViewController {
         }
     }
     
+    @objc func showPlayerToolBar(_ notification: NSNotification) {
+        
+        if let userInfo = notification.userInfo as NSDictionary?, let ocId = userInfo["ocId"] as? String, let enableTimerAutoHide = userInfo["enableTimerAutoHide"] as? Bool{
+            if currentViewController.metadata.ocId == ocId, let ncplayer = currentViewController.ncplayer, !ncplayer.isPictureInPictureActive() {
+                changeScreenMode(mode: .normal, enableTimerAutoHide: enableTimerAutoHide)
+            }
+        }
+    }
+    
     //MARK: - Image
     
     func getImageMetadata(_ metadata: tableMetadata) -> UIImage? {
@@ -503,7 +513,7 @@ extension NCViewerMedia: UIGestureRecognizerDelegate {
         
         if currentScreenMode == .full {
             
-            changeScreenMode(mode: .normal)
+            changeScreenMode(mode: .normal, enableTimerAutoHide: true)
                         
         } else {
             

+ 1 - 1
iOSClient/Viewer/NCViewerMedia/NCViewerMediaZoom.swift

@@ -321,7 +321,7 @@ extension NCViewerMediaZoom {
         scrollView.pinchGestureRecognizer?.isEnabled = true
         if metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue && !metadata.livePhoto && appDelegate.player?.timeControlStatus == .paused {
             if !detailView.isShow() {
-                playerToolBar?.show(enableTimerAutoHide: false)
+                NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShowPlayerToolBar, userInfo: ["ocId":metadata.ocId, "enableTimerAutoHide": false])
             }
         }
     }