فهرست منبع

Remote Command Center

Signed-off-by: marinofaggiana <marino@marinofaggiana.com>
marinofaggiana 3 سال پیش
والد
کامیت
d9b2ce06e7

+ 2 - 0
iOSClient/AppDelegate.swift

@@ -67,6 +67,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     var player: AVPlayer?
     var commandCenterPlayCommand: Any?
     var commandCenterPauseCommand: Any?
+    var commandCenterPreviousCommand: Any?
+    var commandCenterNextCommand: Any?
 
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
         

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

@@ -206,6 +206,12 @@ class NCPlayer: NSObject {
         if let pauseCommand = appDelegate.commandCenterPauseCommand {
             MPRemoteCommandCenter.shared().pauseCommand.removeTarget(pauseCommand)
         }
+        if let previousCommand = appDelegate.commandCenterPreviousCommand {
+            MPRemoteCommandCenter.shared().previousTrackCommand.removeTarget(previousCommand)
+        }
+        if let nextCommand = appDelegate.commandCenterNextCommand {
+            MPRemoteCommandCenter.shared().nextTrackCommand.removeTarget(nextCommand)
+        }
     }
     
     //MARK: - NotificationCenter

+ 20 - 4
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift

@@ -213,6 +213,7 @@ class NCPlayerToolBar: UIView {
                 
                 if !ncplayer.isPlay() {
                     ncplayer.playerPlay()
+                    self.updateToolBar(timeSeek: nil)
                     return .success
                 }
                 return .commandFailed
@@ -223,20 +224,35 @@ class NCPlayerToolBar: UIView {
               
                 if ncplayer.isPlay() {
                     ncplayer.playerPause()
+                    self.updateToolBar(timeSeek: nil)
                     return .success
                 }
                 return .commandFailed
             }
+            
+            // Add handler for Previous Command
+            appDelegate.commandCenterPreviousCommand = commandCenter.previousTrackCommand.addTarget { event in
+                
+                ncplayer.videoSeek(time: .zero)
+                self.updateToolBar(timeSeek: .zero)
+                return.success
+            }
+                
+            // Add handler for Next Command
+            appDelegate.commandCenterNextCommand = commandCenter.nextTrackCommand.addTarget { event in
+                
+                ncplayer.videoSeek(time: .zero)
+                self.updateToolBar(timeSeek: .zero)
+                return.success
+            }
                   
+            nowPlayingInfo[MPMediaItemPropertyTitle] = metadata.fileNameView
+            nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = appDelegate.player?.currentItem?.asset.duration.seconds
             if let image = self.image {
                 nowPlayingInfo[MPMediaItemPropertyArtwork] = MPMediaItemArtwork(boundsSize: image.size) { size in
                     return image
                 }
             }
-            
-            nowPlayingInfo[MPMediaItemPropertyTitle] = metadata.fileNameView
-            nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = appDelegate.player?.currentItem?.asset.duration.seconds
-            
             MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
         }