The Kotlin Camera2 video picture in picture Android development tutorial describes how to add Android 8.0 picture in picture support for video playback.
This Kotlin on Android development tutorial follows on from the Kotlin camera2 ExoPlayer tutorial.
In this Kotlin on Android tutorial we will cover:
- Registering for PIP support
- Adding additional variables to the ViewModel
- Adding video playback state machine
- Adding to video listener to ExoPlayer
- Getting width & height of ExoPlayer video
- Setting aspect ratio for PIP params
- Calling PIP mode
Episodes
- Icons
- MediaRecorder
- Rear Camera Record
- Round preview thumbnail
- Sharing Uri with ViewModel
- Video Playback with ExoPlayer
- Video PIP
- Front Camera Record (Premium)
- Video Record with Audio (Premium)
- Replace TextureView with SurfaceView (Premium)
Disclaimer, it is recommended to follow this Kotlin on Android tutorial series using a Google Pixel or Nexus device.
Please do not try it with the Android Emulator. Bugs have also been observed in camera stacks of none Google devices, which may be exposed by this tutorial series.
Conclusion
In the Kotlin Camera2 video picture in picture Android development tutorial, we described how to implement PIP mode for during the fragment video playback.
Android PIP mode had to be added to main activity in the Android manifest file. Then the onUserLeaveHint() method can be implemented inside the Android activity. The onUserLeaveHint() method will be called when the user selects the home button during the video playback.
A flag was used to monitor video playback state. With Android PIP mode made only available during video playback.
The Android ViewModel was used to pass the video playback status from the ExoPlayerFragment to the main Android activity.
The Exoplayer video aspect ratio was also passed via the Android ViewModel to be used for the PIP parameters.
The following Kotlin tutorial will describe how to switch between front and rear-facing cameras.