marinofaggiana 4 роки тому
батько
коміт
801b8397b1

+ 0 - 5
iOSClient/AppDelegate.h

@@ -76,11 +76,6 @@
 // Passcode lockDirectory
 @property (nonatomic, strong) NSDate *sessionePasscodeLock;
 
-// Audio Video
-@property (nonatomic, strong) AVPlayer *player;
-@property (nonatomic, strong) AVPlayerViewController *playerController;
-@property BOOL isMediaObserver;
-
 // Push Norification Token
 @property (nonatomic, strong) NSString *pushKitToken;
 

+ 2 - 2
iOSClient/AppDelegate.m

@@ -278,8 +278,8 @@
     [[NCBrandColor sharedInstance] settingThemingColor];
     
     // If AVPlayer in play -> Stop
-    if (self.player != nil && self.player.rate != 0) {
-        [self.player pause];
+    if (NCViewerVideoCommon.shared.player != nil && NCViewerVideoCommon.shared.player.rate != 0) {
+        [NCViewerVideoCommon.shared.player pause];
     }
     
     // close detail

+ 4 - 4
iOSClient/Viewer/NCViewerImage/NCViewerImageVideo.swift

@@ -50,12 +50,12 @@ class NCViewerImageVideo: UIViewController {
     
     @IBAction func touchUpInsidecloseButton(_ sender: Any) {
         
-        if appDelegate.player != nil && appDelegate.player.rate != 0 {
-            appDelegate.player.pause()
+        if NCViewerVideoCommon.shared.player != nil && NCViewerVideoCommon.shared.player.rate != 0 {
+            NCViewerVideoCommon.shared.player.pause()
         }
         
-        if appDelegate.isMediaObserver {
-            appDelegate.isMediaObserver = false
+        if NCViewerVideoCommon.shared.isMediaObserver {
+            NCViewerVideoCommon.shared.isMediaObserver = false
             NCViewerVideoCommon.shared.removeObserver()
         }
 

+ 4 - 4
iOSClient/Viewer/NCViewerVideo/NCViewerVideo.swift

@@ -113,12 +113,12 @@ extension NCViewerVideo : UINavigationControllerDelegate {
         super.willMove(toParent: parent)
         
         if parent == nil {
-            if appDelegate.player != nil && appDelegate.player.rate != 0 {
-                appDelegate.player.pause()
+            if NCViewerVideoCommon.shared.player != nil && NCViewerVideoCommon.shared.player.rate != 0 {
+                NCViewerVideoCommon.shared.player.pause()
             }
             
-            if appDelegate.isMediaObserver {
-                appDelegate.isMediaObserver = false
+            if NCViewerVideoCommon.shared.isMediaObserver {
+                NCViewerVideoCommon.shared.isMediaObserver = false
                 NCViewerVideoCommon.shared.removeObserver()
             }
         }

+ 16 - 11
iOSClient/Viewer/NCViewerVideo/NCViewerVideoCommon.swift

@@ -31,6 +31,11 @@ class NCViewerVideoCommon: NSObject {
         return viewVideo
     }()
     
+    // Audio Video
+    @objc var player: AVPlayer!
+    @objc var playerController: AVPlayerViewController!
+    @objc var isMediaObserver: Bool = false
+    
     var metadata: tableMetadata!
     var videoURL: URL?
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
@@ -63,14 +68,14 @@ class NCViewerVideoCommon: NSObject {
             KTVHTTPCache.downloadSetAdditionalHeaders(["Authorization":authValue, "User-Agent":CCUtility.getUserAgent()])
         }
         
-        appDelegate.player = AVPlayer(url: videoURLProxy)
-        appDelegate.playerController = AVPlayerViewController()
+        player = AVPlayer(url: videoURLProxy)
+        playerController = AVPlayerViewController()
         
-        appDelegate.playerController.player = appDelegate.player
-        appDelegate.playerController.view.frame = frame
-        appDelegate.playerController.allowsPictureInPicturePlayback = false
+        playerController.player = player
+        playerController.view.frame = frame
+        playerController.allowsPictureInPicturePlayback = false
         
-        view.addSubview(appDelegate.playerController.view)
+        view.addSubview(playerController.view)
         
         NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: nil, queue: nil) { (notification) in
             let player = notification.object as! AVPlayerItem
@@ -79,10 +84,10 @@ class NCViewerVideoCommon: NSObject {
         
         DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
             
-            self.appDelegate.player.addObserver(self, forKeyPath: "rate", options: [], context: nil)
-            self.appDelegate.isMediaObserver = true
+            self.player.addObserver(self, forKeyPath: "rate", options: [], context: nil)
+            self.isMediaObserver = true
             
-            self.appDelegate.player.play()
+            self.player.play()
         }
     }
     
@@ -90,7 +95,7 @@ class NCViewerVideoCommon: NSObject {
         
         if keyPath != nil && keyPath == "rate" {
             
-            if appDelegate.player.rate == 1 {
+            if player.rate == 1 {
                 print("start")
             } else {
                 print("stop")
@@ -114,7 +119,7 @@ class NCViewerVideoCommon: NSObject {
     
     @objc func removeObserver() {
         
-        appDelegate.player.removeObserver(self, forKeyPath: "rate", context: nil)
+        player.removeObserver(self, forKeyPath: "rate", context: nil)
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil)
     }