Created
January 16, 2020 12:52
-
-
Save halilozercan/9647647d4033258319c0d0cbb89e75b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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