The Kotlin Camera2 API MediaRecorder Android development tutorial describes how to setup the MediaRecorder for recording video from the rear camera.
This Kotlin on Android tutorial follows on from the icons episode.
In this Kotlin on Android tutorial we will cover:
- How to create a unique file name
- How to create an Android File
- Using the SimpleDateFormat class
- Adding value to support display orientation
- Getting sensor orientation from camera characteristics
- Setting up the MediaRecorder
Thes Kotlin specific parts will include
- Using late init delegate
- Kotlin Apply() on objects
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
This Kotlin on Android development tutorial focused on setting up the Android MediaRecorder.
A key point to be aware of when recording video on an Android device is the video orientation.
And in this Kotlin on Android tutorial, we demonstrated how to get the screen display and sensor orientations. And then use those values for setting the correct offsets for the MediaRecorder setOrientationHint value.
The cameraCharacteristics function was also updated to support SENSOR_ORIENTATION key.
The following Kotlin on Android tutorial will describe how to create a video capture session for recording video.