Is there any way to allow PiP functionality only while the user is within an application?
Ideally, the user can launch PiP, but when they background the app the PiP would dismiss and background playback would continue.
Is there any way to allow PiP functionality only while the user is within an application?
Ideally, the user can launch PiP, but when they background the app the PiP would dismiss and background playback would continue.
Copyright © 2021 Jogjafile Inc.
The way to achieve this is by using the
onUserLeaveHint()
callback from the Framework.The example given by the documentation is the opposite of what you're trying to do, but just flip the boolean. ;)
source: https://developer.android.com/guide/topics/ui/picture-in-picture
What the method
iWantToBeInPipModeNow()
does is really up-2-you, but you could intercept that, and exit PiP (if you are in it).You can also ensure your back/stop methods also ensure PiP is handled appropriately for your use case.