Package Index

Horizon logo

Welcome to the Horizon SDK Documentation guide.

Horizon SDK provides an easy to use library for developers who want to add video recording capabilities to their app.

You can check out the provided sample app.

Horizon SDK requires Android 4.3+ (API 18+).

Requirements

Horizon SDK for Android, comes as an aar library that can be used by Android Studio. You can open the aar file as a zip file to observe its contents. The aar package contains:

  • A jar file, which is the binary version of the library.
  • The resources that Horizon SDK needs.
  • A ProGuard configuration file that will be used for the library, if you use ProGuard in your project.
  • An Android.Manifest that will be merged with your app’s manifest.

Horizon’s Android.Manifest requires the following permissions, so that you don’t have to require them again in your Manifest:

  • android.permission.WRITE_EXTERNAL_STORAGE
  • android.permission.CAMERA
  • android.permission.RECORD_AUDIO

Note: if your targetSdkVersion is 23, you will have to request permissions at runtime.

The manifest also requires the following features from a device:

  • android.hardware.camera
  • android:glEsVersion="0x00020000"

Horizon’s minSdkVersion is 18. You can’t set your app’s minSdkVersion lower than 18 .

Installation

First, add the following entry in the repositories section of your project’s build.gradle:

allprojects {
    repositories {
        ....
        flatDir {
            dirs "${rootDir}/libs"
        }
    }
}

Copy horizonsdk.aar in the libs folder relative your project’s root directory.

Next, add the following dependencies in your app module’s build.gradle:

...
dependencies {
    ...
    // HorizonSDK dependencies
    implementation 'com.google.guava:guava:23.5-android'
    implementation 'commons-io:commons-io:2.5'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation(name: 'horizonsdk', ext: 'aar')
}

Also, add the following packagingOptions:

android {
   ...
    packagingOptions {
        ...
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

Now, you are good to go! For more details, you can check out the build.gradle files of the sample app.

Quick Start

Initialization

Ensure you initialize the SDK upon application launch. For most applications, this can be done in onCreate() of your Application class.

The example below contains a placeholder API key, so after placing the code be sure to replace it with your own.

HorizonSDK.init(getApplicationContext(), "PLACEHOLDER API KEY");

Create an HVTCamera object. This can be done in onCreate() of your activity.

mHVTCamera = new HVTCamera(getApplicationContext());

You can also implement the HVTCameraListener interface in order to be notified about the running state, recording and photo capturing status of HVTCamera.

mHVTCamera.setListener(new HVTCameraListener() {
        ...
});

Set the orientation of your activity.

int activityRotation = getWindowManager().getDefaultDisplay().getRotation();
mHVTCamera.setScreenRotation(activityRotation);

If your app supports multiple orientations, follow the instructions provided in setScreenRotation(int).

Select Camera and Size

You can use CameraHelper to learn the number of available cameras in the device and their video and photo resolution. You can set the one you want to HVTCamera:

int facing = mCameraHelper.hasCamera(Camera.CameraInfo.CAMERA_FACING_BACK) ?
            Camera.CameraInfo.CAMERA_FACING_BACK : Camera.CameraInfo.CAMERA_FACING_FRONT;
Size[] sizes = mCameraHelper.getDefaultVideoAndPhotoSize(facing);  // helper method to choose the default size
mHVTCamera.setCamera(facing, sizes[0], sizes[1]);

Video Preview

If you want to display the video preview, you can attach an HVTView:

mCameraPreview = (HVTView) findViewById(R.id.camera_preview);
mHVTCamera.attachPreviewView(mCameraPreview);

In the previous code block, HVTView’s id in the activity’s layout is R.id.camera_preview. Alternatively, HVTView could be created programmaticaly.

Running

Open the camera. This can be done in onResume of your activity.

mHVTCamera.startRunning();

When HVTCamera has started running, your listener’s onStartedRunning() is called. You can now start recording if you want.

Video recording

First, we need to create an HVTCamcorderProfile that will define the movie settings such as audio/video bitrate, audio settings etc. The video size should match the HVTCamera’s output movie size.

Size size = mHVTCamera.getOutputMovieSize();
HVTCamcorderProfile recordingProfile = new HVTCamcorderProfile(size.getWidth(), size.getHeight()); // helper method to create a profile

Provide the output File and start recording:

mHVTCamera.startRecording(mVideoFile, recordingProfile);

When you want to stop recording, call:

mHVTCamera.stopRecording();

When recording has finished, your listener’s onRecordingFinished() will be called.

Note: You can find in depth details on when you can start or stop recording in the documentation and in the sample app.

Stop Running

Stop the camera. This can be called in onPause of your activity.

mHVTCamera.stopRecording();

You can start and stop HVTCamera multiple times. If you don’t plan on using it again, release it:

mHVTCamera.destroy();
mHVTCamera = null;

This can be done in your activity’s onDestroy().

In this guide, we created, started, stopped and released HVTCamera in accordance to the activity’s onCreate(), onResume(), onPause() and onDestroy(). However, HVTCamera can run independently to an Activity’s lifecycle. It can even record while the app is in the background. In such a scenario, it would be best to create a service to avoid Android killing your app while it’s in the background.

Documentation

For in depth details and optmization tips, please read the documentation. You can start with the following classes:

Also, read the comments of the sample app that can be found in the Android.Manifest, the Java classes and the resource files (styles.xml, horizon_sdk_customization.xml, activity_main.xml).

com.hvt.horizonSDK