wenweiwei vor 3 Jahren
Ursprung
Commit
f603020f7c

+ 4 - 4
MusicVideoPlus/AppDelegate.swift

@@ -28,11 +28,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
         wxappInfo.universalLink = "https://shanyin.piaoquantv.com/.well-known/apple-app-site-association"
         wxappInfo.scope = "snsapi_userinfo"
         PQSingletoWXApiUtil.shared.registerApp(appInfo: wxappInfo)
-        
+
         PQSingletoBuglyUtil.shared.registerBugly(appID: "6c481442-aeb4-49ec-a2ae-21359bfef44a")
-        
+
         PQBFConfig.shared.enableBFLog = DEVELOPMENT_ENVIRONMENT == 0
-        
+
         // 注册友盟
         MVThirdApiUtil.registerUM()
         // 注册bugly
@@ -74,7 +74,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
         DispatchQueue.global().async {
             let session = AVAudioSession.sharedInstance()
             do {
-                try session.setCategory(.soloAmbient)
+                try session.setCategory(.playback)
                 BFLog(message: "打开声音活跃关闭其他音乐播放成功")
             } catch {
                 BFLog(message: "打开声音活跃关闭其他音乐播放失败:\(error)")

+ 21 - 1
MusicVideoPlus/Classes/Modules/Mine/Controllers/MVPlayViewController.swift

@@ -80,8 +80,9 @@ class MVPlayViewController: PQBaseViewController {
         PQSingletoVideoPlayer.shared.progressBloc = { [weak self] _, playProgress, duration in
             (self?.collectionView.visibleCell() as? MVPlayControlViewCell)?.updateProgress(progress: playProgress / duration)
         }
-
         PQNotification.addObserver(self, selector: #selector(didBecomeActiveNotification), name: UIApplication.didBecomeActiveNotification, object: nil)
+        PQNotification.addObserver(self, selector: #selector(enterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
+        PQNotification.addObserver(self, selector: #selector(willEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
     }
 
     override func viewDidAppear(_ animated: Bool) {
@@ -122,6 +123,7 @@ class MVPlayViewController: PQBaseViewController {
 
     deinit {
         PQNotification.removeObserver(self)
+        PQSingletoVideoPlayer.shared.stopPlayer()
     }
 }
 
@@ -245,4 +247,22 @@ extension MVPlayViewController: UICollectionViewDelegate, UICollectionViewDataSo
             collectionView.reloadData()
         }
     }
+
+    @objc func enterBackground() {
+        BFLog(message: "进入到后台")
+        let navVc: UINavigationController? = (UIApplication.shared.keyWindow?.rootViewController) as? UINavigationController
+        if navVc?.visibleViewController is MVPlayViewController {
+            (collectionView.visibleCell() as? MVPlayControlViewCell)?.pauseBtn.isSelected = true
+            PQSingletoVideoPlayer.shared.stopPlayer(isRemove:false)
+        }
+    }
+
+    @objc func willEnterForeground() {
+        BFLog(message: "进入到前台")
+        let navVc: UINavigationController? = (UIApplication.shared.keyWindow?.rootViewController) as? UINavigationController
+        if navVc?.visibleViewController is MVPlayViewController {
+            (collectionView.visibleCell() as? MVPlayControlViewCell)?.pauseBtn.isSelected = false
+            PQSingletoVideoPlayer.shared.startPlayr()
+        }
+    }
 }

+ 1 - 1
MusicVideoPlus/PQConfig.plist

@@ -3,6 +3,6 @@
 <plist version="1.0">
 <dict>
 	<key>ENVMode</key>
-	<string>ENVModeOnline</string>
+	<string>ENVModeTest</string>
 </dict>
 </plist>