Video Player shuts down after clicking back button in app while it's in PiP mode

Hi,

During Bitmovin Player is in PiP mode, when we click the back button of our App, video player shuts down. This problem occurs in iOS. Is there any option to solve this issue? You can find the screen recording below:
PiP Shuts Down

Hi @macdigital , thanks for your question. Can you please share PiP related configuration for Bitmovin player and the version of Bitmovin iOS player SDK.

In general, you can find information on PiP related functionality in our community post at Picture-in-Picture support in Bitmovin iOS player SDK

Please check if you are already setting PlayerViewConfig.pictureInPictureConfig.shouldEnterOnBackground as true to allow playback to enter PiP mode when application is backgrounded.

Hi @lucky.goyal ,

Our PiP configuration is written below. Additionally, PiP is working while our App is in background, so we can navigate through other App, but we cannot land another page in our App.

// player config
let playerConfig = PlayerConfig()
playerConfig.styleConfig.userInterfaceType = .system
playerConfig.playbackConfig.isBackgroundPlaybackEnabled = true
playerConfig.playbackConfig.isPictureInPictureEnabled = true
player = PlayerFactory.create(playerConfig: playerConfig)
// source config
let sourceConfig = SourceConfig(url: videoUrl, type: .progressive)
let source = SourceFactory.create(from: sourceConfig)
// player view
let playerView = PlayerView(player: player, frame: .zero)
playerView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
playerView.frame = videoView.bounds
videoView.addSubview(playerView)
player.load(source: source)
player.add(listener: logger)

thanks for sharing the config. It seems that you are not using the new PiP config class as demonstrated in Picture-in-Picture support in Bitmovin iOS player SDK

Can you please try to upgrade to a version >= 3.34.0 and try the new config?

Hi @macdigital,

most likely, this is the case because your AVPlayer instance is deallocated when navigating back in your App.

If you want to keep PiP playback active within the App, you need to retain the AVPlayer instance outside of the video-playback ViewController/View.

Dear David,

Your suggestion worked. Thanks a lot :+1:

We have another question for PiP mode. How can we capture that user activates or deactivates PiP mode? Is there any code example for this issue?

Thanks.

For this we do have the following events which are emitted accordingly:

One remark to that though:
Those events are emitted from the PlayerView which might be a bit tricky in your use-case as the PlayerView instance would deallocate when you navigate back in your App.
So in case the user closes the PiP window, using the X top left, there won’t be any event emitted anymore.

You could try to keep a reference to the PlayerView as well although it’s not needed for the In-App PiP playback.

Hope that helps :slightly_smiling_face:

Thank you very much for your quick turnaround.
We were able to access the methods and tried to use necessary functions by conforming the UserInterfaceListener. But none of the functions are being triggered.
Similarly, we can trigger the functions belonging to PlayerListener. Below is the code example. We would appreciate your help.

override public func viewDidLoad() {
    super.viewDidLoad()
...
...
...
player.add(listener: self)
}
extension VideoPlayerViewController: UserInterfaceListener {
  public func onPictureInPictureEnter(_ event: PictureInPictureEnterEvent, view: PlayerView) {
    print("onPictureInPictureEnter")
  }
  public func onPictureInPictureEntered(_ event: PictureInPictureEnteredEvent, view: PlayerView) {
    print("onPictureInPictureEntered")
  }
  public func onPictureInPictureExit(_ event: PictureInPictureExitEvent, view: PlayerView) {
    print("onPictureInPictureExit")
  }
  public func onPictureInPictureExited(_ event: PictureInPictureExitedEvent, view: PlayerView) {
    print("onPictureInPictureExited")
  }
}

In order to receive the PiP-related events you need to add this listener to the PlayerView and not the Player.

playerView.add(listener: self)

instead of

player.add(listener: self)

However, as mentioned above, the PlayerView instance will be released as soon as you navigate back in your Application.

One possibility to workaround this (if needed) would be to also retain the PlayerView reference where you retain the Player. This, unfortunately, adds a memory overhead just for retrieving those events.