Camera2-Video


Source link: https://github.com/WesleyElliott/Camera2-Video

Camera2-Video

A simple Android wrapper for interfacing with the new Camera2 API for video capture.

Usage

Setup

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:

  1. getTextureResource - this needs to return an ID for an com.wesley.camera2.widget.AutoFitTextureView in your layout.
  2. getVideoFile - this needs to return a File for the MediaRecorder to 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.

Customisation

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:

  1. setUpCaptureRequestBuilder(CaptureRequest.Builder builder) - the default setup only does builder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO); , however, you can override setUpCaptureRequestBuilder and build the CaptureRequest yourself.
  2. protected void setUpMediaRecorder() throws IOException - care needs to be taken when overriding this method. If you need to customise any MediaRecorder settings, 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

setRationaleMessage(String message)

or

setRationaleMessage(int messageResource)

Error Handling

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);
  • void onConfigurationFailed();

Download

Either download using Gradle:

compile 'com.wesleyelliott:camera2-video:0.0.2'

or Maven:

dependency>
<groupId>com.wesleyelliott</groupId>
<artifactId>camera2-video</artifactId>
<version>0.0.2</version>
<type>pom</type> </dependency> 

Resources

An extension for Google's AutoValue that generates a createFromCursor(Cursor c) method for AutoValue annotated objects.

Quota widget for Android.

Drag & Drop GridView on Android.

If you are tired of constantly having to set up progress bars, empty views and error views, than this library is for you.

Quick solutions for Android ORM.

A different beautiful ViewPager, with quick swipe controls.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes