Giter Site home page Giter Site logo

msoftware / camera2-video Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wesleyelliott/camera2-video

0.0 2.0 0.0 74 KB

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

License: Apache License 2.0

Java 100.00%

camera2-video's Introduction

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>

camera2-video's People

Contributors

wesleyelliott avatar

Watchers

Michael jentsch avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.