iOS 14 Play audio from video in background

Replies

I've just got the same isue. And you posted the question before me :)
  • Disconnecting player by 'AVPlayerLayer.player = nil' won't catch when appDidEnterBackGround, but it will be catch when appWillResignActive.

  • The problem is: when player is playing, user push locked button, phone goes directly to backgroundMode, and app 'AVPlayerLayer.player = nil'. So the player is paused. User have to click play button at lockedScreen to continue playing in background mode.

I don't know when Apple fix this
@tungdangplus Thank you for your answer! It works for me.
@tungdangplus 

That didn't work for me. In AppDelegate, I did:

Code Block
    func applicationWillResignActive(_ application: UIApplication) {
        let viewController = window?.rootViewController as! ViewController
        viewController.disconnectAVPlayer()
    }



and then in ViewController, I did:

Code Block
    public func disconnectAVPlayer() {
      playerViewController.player = nil
    }