Address to the problem that the video is paused during background transition while playing video on iOS14
Correspondence
playerView.player = nil
playerView.player = player
** Change the execution timing of **
@objc func applicationWillResignActive(_ notification: NSNotification?) {
playerView.player = nil
}
@objc func applicationDidBecomeActive(_ notification: NSNotification?) {
playerView.player = player
}
Background
- User "Background playback is strange after updating to iOS14. Somehow: rage :: bangbang:"
- Watakushi ": sob:"
Before correspondence
- ʻApplicationDidEnterBackground
was
playerView.player = nil` * According to the contents of the document published by Apple
Survey
- It stopped working even though I didn't do anything ⇒ OS specifications have changed?
- Pause when going to the background ⇒ Is it the same as the operation with the player set in the layer?
Verification
- Manually
playerView.player = nil
during video playback and before background migration
- Go to background
⇒ ** "Playback continued!" **
The conclusion drawn is ...
** "Isn't the timing of checking if there is a player in the layer changed?" **
Revalidation
- Changed to
playerView.player = nil
in ** ʻapplicationWillResignActive ** that runs before ʻapplicationDidEnterBackground
- ʻapplicationWillResignActive
is paired with ** ʻapplicationDidBecomeActive
**, so change to playerView.player = player
.
⇒ ** "Playback continued!" **
- We have also confirmed that it works on iOS 11-14 and iPad OS 13 and 14.
Summary
- Even if you write it as Apple's document, it will not work, so there is a high possibility of an OS malfunction.
- It is rumored that this bug has been fixed in iOS 14.2 beta2.
Other
- It's been a while since iOS14 was released, but I haven't seen this solution, so I'll post an article.
References
- Apple : Playing media while in the background using AV Foundation on iOS
- Apple : Playing Audio from a Video Asset in the Background
- @KenNagami: iOS App Lifecycle
- @bosteri_bon: Fixed the problem that "background playback" is not possible on iOS14