why onPictureInPictureModeChanged method is not working?

14 Views Asked by At

I am trying to implement Picture in Picture in my app It is perfectly entering in PiP mode.

The problem is that the override method onPictureInPictureModeChanged method is not called when entering PIP mode.

My onPictureInPictureModeChanged method is showing an error

override method should call super.onPictureInPictureModeChanged

My minSdk 24 and targetSdk 33

private fun pictureInPictureMode(){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
        Log.d(TAG, "pictureInPictureMode: Supports PIP")
        val aspectRatio = Rational(videoView.width, videoView.height)
        pictureInPictureParamsBuilder!!.setAspectRatio(aspectRatio).build()
        enterPictureInPictureMode(pictureInPictureParamsBuilder!!.build())
    }
    else{
        Toast.makeText(this, "Your device doesn't supports PIP", 
        Toast.LENGTH_LONG).show()
    }
}


override fun onPictureInPictureModeChanged(
    isInPictureInPictureMode: Boolean,
    newConfig: Configuration?
) {
    super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
    if (isInPictureInPictureMode){
        Log.d(TAG, "onPictureInPictureModeChanged: Entered PIP")
        pipButton.visibility = View.GONE
    }
    else{
        Log.d(TAG, "onPictureInPictureModeChanged: Exited PIP")
        pipButton.visibility = View.VISIBLE
    }
}
0

There are 0 best solutions below