I have an App in which I use AVPlayerLayer (used within a subclass of UIView just like Apples AV Foundation Programming Guide). Ihave a couple of view controllers witch are held in the View Controller that is resonsible for the menu (JASidePanels are used). The problem is as follows:
Everything works ok until the view controller with the AVPlayers does'nt get hidden (some other view is presented) and the the app enters background, gets back again and returns to the view. This Causes the AVPlayerLayer to display blank/transparent. The item is loaded as well as i can try playing it and indeed it is played but no video is seen.
What is the solution to this behaviour (and what is the cause of it)? Thx in advance.
player?.seek(to: .zero)
triggers AVPlayerLayer
to render preview.
To smoothly update and pause the video on closing/opening the app in my case I've added the following:
private func setupObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(willResignActive), name: UIApplication.willResignActiveNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didBecomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)
}
@objc
private func willResignActive() {
player?.pause()
}
@objc
private func didBecomeActive() {
player?.seek(to: .zero)
}
I'm not sure what causes it but a solution that worked for me was to reset the player on the AVPlayerLayer
avPlayerLayer = AVPlayerLayer(player: currentAvPlayer)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With