The Kotlin Camera2 API ViewModel sharing Uri Android development tutorial describes how to share a video Uri between Android fragments using the ViewModel.
Another Kotlin ViewModel tutorial is also available here. And describes how to share an Android Uri between two fragments.
This Kotlin on Android development tutorial follows on from the video thumbnail tutorial. And will focus on sharing data using the Android ViewModel.
In this Kotlin on Android tutorial we will cover:
- Installing the ViewModel
- Creating a ViewModel class
- Instantiating the ViewModel inside Android Fragments
- Setting and getting the ViewModel values
- Creating an Android Fragment from scratch
- Replacing an Android fragment from inside a fragment
- 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.
This Kotlin on Android tutorial described how to pass a Uri from one Android fragment to another fragment using the Android ViewModel.
Installing the ViewModel library and creating the ViewModel class was straightforward. Then inside each Android fragment, an instance of the ViewModel class was created. And in this Kotlin on Android tutorial, we used the Kotlin lazy delegate value to hold the ViewModel instance.
And then it was just a matter of using the Kotlin style of setting and getting the video Uri value.
This Kotlin on Android tutorial also demonstrated how to replace an Android fragment from inside a fragment.
The following Kotlin tutorial will describe how to playback the captured video using ExoPlayer.