Skip to content

Instantly share code, notes, and snippets.

@tfaki
Created October 14, 2022 06:57
Show Gist options
  • Save tfaki/fd74617d310188039df8c6eb2ce78611 to your computer and use it in GitHub Desktop.
Save tfaki/fd74617d310188039df8c6eb2ce78611 to your computer and use it in GitHub Desktop.
private fun pictureInPictureMode(){
//Requires Android O and higher
Log.d(TAG, "pictureInPictureMode: Try to enter in PIP mode")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
Log.d(TAG, "pictureInPictureMode: Supports PIP")
//setup PIP height width
val aspectRatio = Rational(videoView.width, videoView.height)
pictureInPictureParamsBuilder!!.setAspectRatio(aspectRatio).build()
enterPictureInPictureMode(pictureInPictureParamsBuilder!!.build())
}
else{
Log.d(TAG, "pictureInPictureMode: Doesn't supports PIP")
Toast.makeText(this, "Your device doesn't supports PIP", Toast.LENGTH_LONG).show()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment