Skip to content

Instantly share code, notes, and snippets.

@halilozercan
Created January 16, 2020 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halilozercan/9647647d4033258319c0d0cbb89e75b4 to your computer and use it in GitHub Desktop.
Save halilozercan/9647647d4033258319c0d0cbb89e75b4 to your computer and use it in GitHub Desktop.
private fun startPictureInPicture(): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && shouldStart) {
enterPictureInPictureMode(
PictureInPictureParams.Builder()
.setAspectRatio(…) // This has lower and upper limitations
.build()
)
return true
}
return false
}
override fun onUserLeaveHint() {
super.onUserLeaveHint()
startPictureInPicture()
}
override fun onBackPressed() {
if (!startPictureInPicture()) {
super.onBackPressed() // Only execute if PiP is not started
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment