Эх сурвалжийг харах

Remote Command Center // Test

Signed-off-by: marinofaggiana <marino@marinofaggiana.com>
marinofaggiana 3 жил өмнө
parent
commit
e4820b7f78

+ 2 - 0
iOSClient/AppDelegate.swift

@@ -257,6 +257,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         if let directory = CCUtility.getDirectoryProviderStorage() {
             NCUtilityFileSystem.shared.cleanUp(directory: directory, days: TimeInterval(days))
         }
+        
+        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterApplicationWillResignActive)
     }
     
     // L' applicazione è entrata nello sfondo

+ 1 - 0
iOSClient/NCGlobal.swift

@@ -314,6 +314,7 @@ class NCGlobal: NSObject {
     @objc let notificationCenterApplicationDidEnterBackground   = "applicationDidEnterBackground"
     let notificationCenterApplicationWillEnterForeground        = "applicationWillEnterForeground"
     let notificationCenterApplicationDidBecomeActive            = "applicationDidBecomeActive"
+    let notificationCenterApplicationWillResignActive           = "applicationWillResignActive"
 
     @objc let notificationCenterInitialize                      = "initialize"
     @objc let notificationCenterChangeTheming                   = "changeTheming"

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

@@ -26,6 +26,7 @@ import NCCommunication
 import UIKit
 import AVFoundation
 import AVKit
+import MediaPlayer
 
 /// The Set of custom player controllers currently using or transitioning out of PiP
 private var activeNCPlayer = Set<NCPlayer>()
@@ -146,6 +147,8 @@ class NCPlayer: NSObject {
             }
         })
         
+        NotificationCenter.default.addObserver(self, selector: #selector(generatorImagePreview), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationWillResignActive), object: nil)
+        
         NotificationCenter.default.addObserver(self, selector: #selector(applicationDidEnterBackground(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidEnterBackground), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidBecomeActive), object: nil)
     }
@@ -153,6 +156,8 @@ class NCPlayer: NSObject {
     deinit {
         print("deinit NCPlayer")
         
+        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationWillResignActive), object: nil)
+        
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidEnterBackground), object: nil)
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidBecomeActive), object: nil)
 
@@ -249,7 +254,7 @@ class NCPlayer: NSObject {
         self.saveTime(time)
     }
     
-    func generatorImagePreview() {
+    @objc func generatorImagePreview() {
         guard let time = appDelegate.player?.currentTime() else { return }
         guard let metadata = self.metadata else { return }
         if metadata.livePhoto { return }
@@ -266,6 +271,12 @@ class NCPlayer: NSObject {
                 imageGenerator.appliesPreferredTrackTransform = true
                 let cgImage = try imageGenerator.copyCGImage(at: time, actualTime: nil)
                 image = UIImage(cgImage: cgImage)
+                // Update Playing Info Center
+                if let image = image {
+                    MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPMediaItemPropertyArtwork] = MPMediaItemArtwork(boundsSize: image.size) { size in
+                        return image
+                    }
+                }
                 // Preview
                 if let data = image?.jpegData(compressionQuality: 0.5) {
                     try data.write(to: URL.init(fileURLWithPath: fileNamePreviewLocalPath), options: .atomic)