Browse Source

Remote Command Center

Signed-off-by: marinofaggiana <marino@marinofaggiana.com>
marinofaggiana 3 years ago
parent
commit
e8ccad649a

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

@@ -80,11 +80,12 @@ class NCPlayer: NSObject {
         // At end go back to start & show toolbar
         observerAVPlayerItemDidPlayToEndTime = NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: appDelegate.player?.currentItem, queue: .main) { (notification) in
             if let item = notification.object as? AVPlayerItem, let currentItem = self.appDelegate.player?.currentItem, item == currentItem {
+                NCKTVHTTPCache.shared.saveCache(metadata: metadata)
                 self.videoSeek(time: .zero)
                 if !(detailView?.isShow() ?? false) {
                     NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShowPlayerToolBar, userInfo: ["ocId":metadata.ocId, "enableTimerAutoHide": false])
                 }
-                NCKTVHTTPCache.shared.saveCache(metadata: metadata)
+                playerToolBar?.updateToolBar(timeSeek: .zero, commandCenter: true)
             }
         }
         

+ 8 - 8
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift

@@ -148,12 +148,7 @@ class NCPlayerToolBar: UIView {
             labelOverallDuration.text = "-" + NCUtility.shared.stringFromTime(durationTime)
         }
         
-        // COMMAND CENTER
-        if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
-            endableCommandCenter()
-        }
-        
-        updateToolBar(timeSeek: timeSeek)
+        updateToolBar(timeSeek: timeSeek, commandCenter: true)
         
         self.timeObserver = appDelegate.player?.addPeriodicTimeObserver(forInterval: CMTimeMakeWithSeconds(1, preferredTimescale: 1), queue: .main, using: { (CMTime) in
             
@@ -165,12 +160,17 @@ class NCPlayerToolBar: UIView {
         })
     }
     
-    public func updateToolBar(timeSeek: CMTime? = nil) {
+    public func updateToolBar(timeSeek: CMTime? = nil, commandCenter: Bool = false) {
         guard let metadata = self.metadata else { return }
         
         var currentTime = appDelegate.player?.currentTime() ?? .zero
         currentTime = currentTime.convertScale(1000, method: .default)
         
+        // COMMAND CENTER
+        if commandCenter && CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
+            enableCommandCenter()
+        }
+        
         // MUTE
         if CCUtility.getAudioMute() {
             muteButton.setImage(NCUtility.shared.loadImage(named: "audioOff", color: .white), for: .normal)
@@ -242,7 +242,7 @@ class NCPlayerToolBar: UIView {
     
     // MARK: - Command Center
     
-    func endableCommandCenter() {
+    func enableCommandCenter() {
         guard let ncplayer = self.ncplayer else { return }
         
         UIApplication.shared.beginReceivingRemoteControlEvents()