Browse Source

1,进入前后台 播放器,导出控制,2,进入活跃非活跃状态 播放器控制

jsonwang 3 years ago
parent
commit
954d31ff10
1 changed files with 52 additions and 0 deletions
  1. 52 0
      Introduce/Record/INVideoExportController.swift

+ 52 - 0
Introduce/Record/INVideoExportController.swift

@@ -248,13 +248,65 @@ class INVideoExportController: BFBaseViewController {
 
     override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(animated)
+        
+        
+        PQNotification.addObserver(self, selector: #selector(enterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
+        PQNotification.addObserver(self, selector: #selector(willEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
+        
+        //进入活跃状态
+        PQNotification.addObserver(self, selector: #selector(didBecomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)
+        
+        //进入非活跃状态
+        PQNotification.addObserver(self, selector: #selector(willResignActive), name: UIApplication.willResignActiveNotification, object: nil)
+
         showNavigation()
         // 曝光上报
         BFEventTrackAdaptor.baseReportUpload(businessType: .bt_pageView, objectType: nil, pageSource: .sp_composePage, commonParams: commonParams())
     }
+    @objc func didBecomeActive(){
+        BFLog(message: "进入活跃状态")
+        if let sbtn = sliderView?.viewWithTag(1) as? UIButton ,!isExporting {
+            sbtn.isSelected = false
+            avplayer.play()
+        }
+    }
+    
+    @objc func willResignActive(){
+        BFLog(message: "进入非活跃状态")
+        if let sbtn = sliderView?.viewWithTag(1) as? UIButton  , !isExporting{
+            sbtn.isSelected = true
+            avplayer.pause()
+        }
+    }
+    
+    
+    @objc func enterBackground() {
+        BFLog(message: "进入到后台")
+        
+        if isExporting {
+            self.export.cancelExport()
+        }else{
+            if let sbtn = sliderView?.viewWithTag(1) as? UIButton {
+                sbtn.isSelected = true
+                avplayer.pause()
+            }
+        }
+
+    }
+
+    @objc func willEnterForeground() {
+        BFLog(message: "进入到前台")
+        export.startExprot(synthesisAll: saveAllBtn.isSelected)
+        //重启播放器
+        if let sbtn = sliderView?.viewWithTag(1) as? UIButton {
+            sbtn.isSelected = false
+            avplayer.play()
+        }
+    }
 
     override func viewWillDisappear(_ animated: Bool) {
         super.viewWillDisappear(animated)
+        PQNotification.removeObserver(self)
         UIApplication.shared.isIdleTimerDisabled = false
     }