1

I am trying to implement pip mode in android. There is a LiveStreamActivity which contains these elements: Header layout, VideoStream layout and custom popup that I show programatically. Their contexts are the same: LiveStreamActivity. When I enter pip mode LiveStreamActivity's root layout shrinks and fits in small pip screen. But I only want to show VideoStream layout.

I tried setSourceRectHint to achieve this but it does not work. Summary : How to show desired view (or views) in pip mode?

override fun onUserLeaveHint() {

            val visibleRect = Rect()
            mBinding.videoStreamLayout.getGlobalVisibleRect(visibleRect)

            enterPictureInPictureMode(PictureInPictureParams.Builder()
                .setAspectRatio(Rational(9,16))
                .setAutoEnterEnabled(true)
                .setSourceRectHint(visibleRect)
                .setSeamlessResizeEnabled(false)
                .build())
        

        super.onUserLeaveHint()
    } 

image that describes the situation

alpertign
  • 296
  • 1
  • 4
  • 13

1 Answers1

0

Override Activity.onPictureInPictureModeChanged() or Fragment.onPictureInPictureModeChanged() callback and change header and popup visibility.

override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) {
    super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)

    if (isInPictureInPictureMode) {
        // Hide header and popup
    } else {
        // Show header and popup
    }
}
Alexander
  • 316
  • 1
  • 7