瀏覽代碼

fix pip

Signed-off-by: marinofaggiana <marino@marinofaggiana.com>
marinofaggiana 3 年之前
父節點
當前提交
28f75773b3

+ 0 - 6
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift

@@ -99,12 +99,6 @@ class NCPlayer: NSObject {
                         DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
                             imageVideoContainer.image = imageVideoContainer.image?.image(alpha: 0)
                         }
-                        
-                        // PIP
-                        if let playerLayer = self.videoLayer, metadata.livePhoto == false {
-                            self.pictureInPictureController = AVPictureInPictureController(playerLayer: playerLayer)
-                            self.pictureInPictureController?.delegate = self
-                        }
                     }
                     
                     self.playerToolBar?.setBarPlayer(ncplayer: self, metadata: metadata, image: imageVideoContainer.image)

+ 13 - 11
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift

@@ -152,17 +152,11 @@ class NCPlayerToolBar: UIView {
         if metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue {
             pipButton.setImage(NCUtility.shared.loadImage(named: "pip.enter", color: .white), for: .normal)
             pipButton.isEnabled = true
-            if let playerLayer = ncplayer.videoLayer, ncplayer.pictureInPictureController == nil {
-                ncplayer.pictureInPictureController = AVPictureInPictureController(playerLayer: playerLayer)
-                ncplayer.pictureInPictureController?.delegate = ncplayer
-            }
         } else {
             pipButton.setImage(NCUtility.shared.loadImage(named: "pip.enter", color: .gray), for: .normal)
             pipButton.isEnabled = false
-            if ncplayer.pictureInPictureController != nil {
-                ncplayer.pictureInPictureController = nil
-                ncplayer.pictureInPictureController?.delegate = nil
-            }
+            ncplayer.pictureInPictureController = nil
+            ncplayer.pictureInPictureController?.delegate = nil
         }
         
         // SLIDER TIME (START - END)
@@ -460,9 +454,17 @@ class NCPlayerToolBar: UIView {
     
     @IBAction func setPip(_ sender: Any) {
         guard let metadata = self.metadata else { return }
-
-        ncplayer?.pictureInPictureController?.startPictureInPicture()
-        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterHidePlayerToolBar, userInfo: ["ocId":metadata.ocId])
+        
+        if let ncplayer = self.ncplayer, let playerLayer = ncplayer.videoLayer {
+            if ncplayer.pictureInPictureController == nil {
+                ncplayer.pictureInPictureController = AVPictureInPictureController(playerLayer: playerLayer)
+                ncplayer.pictureInPictureController?.delegate = ncplayer
+            }
+            if let pictureInPictureController = ncplayer.pictureInPictureController, pictureInPictureController.isPictureInPicturePossible {
+                ncplayer.pictureInPictureController?.startPictureInPicture()
+                NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterHidePlayerToolBar, userInfo: ["ocId":metadata.ocId])
+            }
+        }
     }
     
     @IBAction func forwardButtonSec(_ sender: Any) {