瀏覽代碼

Remote Command Center // Test

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

+ 0 - 15
iOSClient/AppDelegate.swift

@@ -141,9 +141,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         UNUserNotificationCenter.current().delegate = self
         UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (_, _) in }
 
-        // Audio Session
-        setAVAudioSession()
-        
         // Store review
         if !NCUtility.shared.isSimulatorOrTestFlight() {
             let review = NCStoreReview()
@@ -325,18 +322,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         //[fileProviderDomain removeAllDomains];
         //[fileProviderDomain registerDomains];
     }
-  
-    // MARK: - AVAudioSession
-    
-    func setAVAudioSession() {
-        do {
-            try AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSession.PortOverride.none)
-            try AVAudioSession.sharedInstance().setCategory(.playback, mode: .moviePlayback, options: [.mixWithOthers, .allowAirPlay])
-            try AVAudioSession.sharedInstance().setActive(true)
-        } catch {
-            print(error)
-        }
-    }
     
     // MARK: - Background Task
     

+ 13 - 6
iOSClient/Main/AudioRecorder/NCAudioRecorderViewController.swift

@@ -85,7 +85,6 @@ class NCAudioRecorderViewController: UIViewController , NCAudioRecorderDelegate
             startStop()
         } else {
             dismiss(animated: true) {
-                self.appDelegate.setAVAudioSession()
                 self.delegate?.didFinishWithoutRecording(self, fileName: self.fileName)
             }
         }
@@ -100,7 +99,6 @@ class NCAudioRecorderViewController: UIViewController , NCAudioRecorderDelegate
             voiceRecordHUD.update(0.0)
         
             dismiss(animated: true) {
-                self.appDelegate.setAVAudioSession()
                 self.delegate?.didFinishRecording(self, fileName: self.fileName)
             }
             
@@ -179,7 +177,6 @@ open class NCAudioRecorder : NSObject {
     open var sampleRate = 44100.0
     open var channels = 1
     
-    fileprivate let session = AVAudioSession.sharedInstance()
     var recorder: AVAudioRecorder?
     fileprivate var player: AVAudioPlayer?
     fileprivate var link: CADisplayLink?
@@ -195,9 +192,19 @@ open class NCAudioRecorder : NSObject {
         super.init()
         
         do {
-            try session.setCategory(.playAndRecord, mode: .default)
-            try session.overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)
-            try session.setActive(true)
+            try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default)
+            try AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)
+            try AVAudioSession.sharedInstance().setActive(true)
+        } catch {
+            print(error)
+        }
+    }
+    
+    deinit {
+        print("deinit NCAudioRecorder")
+        
+        do {
+            try AVAudioSession.sharedInstance().setActive(false)
         } catch {
             print(error)
         }

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

@@ -112,7 +112,7 @@ class NCPlayer: NSObject {
                     if let durationTime: CMTime = (self.appDelegate.player?.currentItem?.asset.duration) {
                         NCManageDatabase.shared.addVideoTime(metadata: metadata, time: nil, durationTime: durationTime)
                     }
-                    self.playerToolBar?.setBarPlayer(ncplayer: self, timeSeek: timeSeek, metadata: metadata)
+                    self.playerToolBar?.setBarPlayer(ncplayer: self, timeSeek: timeSeek, metadata: metadata, image: imageVideoContainer?.image)
                     self.generatorImagePreview()
                     if !(detailView?.isShow() ?? false) {
                         NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShowPlayerToolBar, userInfo: ["ocId":metadata.ocId, "enableTimerAutoHide": false])

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

@@ -54,6 +54,7 @@ class NCPlayerToolBar: UIView {
     private var timeObserver: Any?
     private var timerAutoHide: Timer?
     private var metadata: tableMetadata?
+    private var image: UIImage?
 
     // MARK: - View Life Cycle
 
@@ -174,11 +175,11 @@ class NCPlayerToolBar: UIView {
         }
     }
     
-    func setBarPlayer(ncplayer: NCPlayer, timeSeek: CMTime, metadata: tableMetadata) {
+    func setBarPlayer(ncplayer: NCPlayer, timeSeek: CMTime, metadata: tableMetadata, image: UIImage?) {
                         
         self.ncplayer = ncplayer
         self.metadata = metadata
-        
+                
         if let durationTime = NCManageDatabase.shared.getVideoDurationTime(metadata: ncplayer.metadata) {
         
             self.durationTime = durationTime
@@ -191,6 +192,7 @@ class NCPlayerToolBar: UIView {
             labelCurrentTime.text = NCUtility.shared.stringFromTime(.zero)
             labelOverallDuration.text = "-" + NCUtility.shared.stringFromTime(durationTime)
         }
+        setupRemoteTransportControls()
         updateToolBar(timeSeek: timeSeek)
         
         self.timeObserver = appDelegate.player?.addPeriodicTimeObserver(forInterval: CMTimeMakeWithSeconds(1, preferredTimescale: 1), queue: .main, using: { (CMTime) in
@@ -444,8 +446,13 @@ extension NCPlayerToolBar {
     func setupRemoteTransportControls() {
         guard let ncplayer = ncplayer else { return }
 
+        UIApplication.shared.beginReceivingRemoteControlEvents()
+        
         let commandCenter = MPRemoteCommandCenter.shared()
-      
+        var nowPlayingInfo = [String : Any]()
+
+        commandCenter.playCommand.isEnabled = true
+        
         // Add handler for Play Command
         commandCenter.playCommand.addTarget { event in
             
@@ -465,23 +472,19 @@ extension NCPlayerToolBar {
             }
             return .commandFailed
         }
-    }
-    
-    func setupNowPlaying() {
         
-        var nowPlayingInfo = [String : Any]()
         nowPlayingInfo[MPMediaItemPropertyTitle] = metadata?.fileNameView
       
-//        if let image = UIImage(named: "artist") {
-//            nowPlayingInfo[MPMediaItemPropertyArtwork] = MPMediaItemArtwork(boundsSize: image.size) { size in
-//                return image
-//            }
-//        }
+        if let image = self.image {
+            nowPlayingInfo[MPMediaItemPropertyArtwork] = MPMediaItemArtwork(boundsSize: image.size) { size in
+                return image
+            }
+        }
         
         nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = appDelegate.player?.currentTime
         nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = appDelegate.player?.currentItem?.asset.duration
         nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = appDelegate.player?.rate
-      
+              
         MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
     }