A simple Android wrapper for interfacing with the new Camera2 API for video capture.
This is not being maintained anymore. Issue's wont be addressed, but you're more than welcome to contribute any changes
For an example, check out the sample app included.
Firstly, create a
Fragment and extend
com.wesley.camera2.fragment.Camera2Fragment. You will be required to override the following methods:
getTextureResource- this needs to return an ID for an
com.wesley.camera2.widget.AutoFitTextureViewin your layout.
getVideoFile- this needs to return a
MediaRecorderto save to (ie: where the video will be saved to).
Start and Stop Recording
To start recording, simply call
startRecordingVideo() and to stop, use
stopRecordingVideo(). Once stopped, the video is saved to disk and the
MediaRecorder is setup again to start a new recording. To check if the app is currently recording a video or not, a method
isRecording() is provided.
The new Camera2 API has greatly changed how to interface with the camera. This library doesn't provide complete customisation, but it does allow override a few setup methods:
setUpCaptureRequestBuilder(CaptureRequest.Builder builder)- the default setup only does
builder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);, however, you can override
setUpCaptureRequestBuilderand build the CaptureRequest yourself.
protected void setUpMediaRecorder() throws IOException- care needs to be taken when overriding this method. If you need to customise any
MediaRecordersettings, overriding this method will allow that. Currently, the encoding frame rate is set to 30, and the bit rate to 1600
With Marshmallow, permissions are granted (or denied) at runtime. This library takes care of all that, including the rationale prompt (a dialog explaining why you need permission to use the feature - only shown if the user continuously denies permission). To customise the rationale message, during
onCreate() simply call
All exceptions related to file handling and camera setup are caught. Default behaviour is to
Log the exception. If you need to manually handle these, override one or more of the following:
void onCameraException(CameraAccessException cae);
void onNullPointerException(NullPointerException npe);
void onInterruptedException(InterruptedException ie);
void onIOException(IOException ioe);
Either download using Gradle:
dependency> <groupId>com.wesleyelliott</groupId> <artifactId>camera2-video</artifactId> <version>0.0.2</version> <type>pom</type> </dependency>