Skip to main content

Photo Taking and Video Recording Functionalities

1. Overview

With the AUTEL SDK, you can configure multiple camera parameters, including the resolution, FPS, exposure settings, image settings, and file type, and implement photo taking and video recording functionalities. This tutorial is designed for you to gain a basic understanding of how to use camera APIs provided by AUTEL SDK. In this tutorial, we will implement three basic camera functionalities: Taking photos, Recording videos, and Setting camera parameters. The following takes an AUTEL SDK demo as an example to explain how to develop the three basic functionalities.

2. Configure an Android Studio Project

2.1 Create an Android Project

2.2 Import an AAR Package

Copy the AAR package to the libs directory of your project and add the following lines of code to the build.gradle file, as shown below:

repositories {
flatDir {
dirs 'libs'
}
}
implementation(name: 'libqxwz_release_v1.1.0', ext: 'aar')

2.3 Add Basic Permissions to the AndroidManifest.xml File

 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

3. Quick Start

3.1 Obtain the Camera API Class Take CameraBaseFragment in the demo as an example:

AutelBaseCamera baseCamera;
baseCamera = ((CameraActivity) getActivity()).getCurrentCamera();

After you obtain AutelBaseCamera, you can perform a series of settings on the camera.

3.2 AutelBaseCamera API Class and Its Methods

 /**
* Listens for the callback of the camera mode setting result
* @param var1
*/
void setMediaModeListener(CallbackWithOneParam<MediaMode> var1);

/**
* Listens for the SD card status
* @param var1
*/
void setSDCardStateListener(CallbackWithOneParam<SDCardState> var1);

/**
* Listens for camera actions
* @param var1
*/
void setMediaStateListener(CallbackWithTwoParams<MediaStatus, String> var1);

/**
* Listens for the camera action completion result
* @param var1
*/
void setMediaStateWithIdListener(CallbackWithThreeParams<MediaStatus, String, String> var1);

/**
* Formats the SD card
* @param var1
*/
void formatSDCard(CallbackWithNoParam var1);

/**
* Resets camera settings
* @param var1
*/
void resetDefaults(CallbackWithNoParam var1);

/**
* Obtains the work status of the camera
* @param var1
*/
void getWorkState(CallbackWithOneParam<WorkState> var1);

/**
* Obtains the SD card status
* @param var1
*/
void getSDCardState(CallbackWithOneParam<SDCardState> var1);

/**
* Obtains the memory of the SD card
* @param var1
*/
void getSDCardFreeSpace(CallbackWithOneParam<Long> var1);

/**
* Obtains the camera model
* @return
*/
CameraProduct getProduct();

/**
* Obtains the camera version
* @param var1
*/
void getVersion(CallbackWithOneParam<String> var1);

/**
* Sets the work mode of the camera
* @param var1: camera mode
* @param var2
*/
void setMediaMode(MediaMode var1, CallbackWithNoParam var2);

/**
* Obtains the camera mode
* @param var1
*/
void getMediaMode(CallbackWithOneParam<MediaMode> var1);

/**
* Starts photo taking
* @param var1
*/
void startTakePhoto(CallbackWithNoParam var1);

/**
* Starts video recording
* @param var1
*/
void startRecordVideo(CallbackWithNoParam var1);

/**
* Stops video recording
* @param var1
*/
void stopRecordVideo(CallbackWithNoParam var1);

/**
* Stops photo taking
* @param var1
*/
void stopTakePhoto(CallbackWithNoParam var1);

/**
* Obtains the current time when the video recording starts
* @param var1
*/
void getCurrentRecordTime(CallbackWithOneParam<Integer> var1);

/**
* Obtains the status information
* @param var1
*/
void getStateInfo(CallbackWithOneParam<BaseStateInfo> var1);

/**
* Configures the camera UI mode
* @param var1: camera UI mode
* @param var2
*/
void setCameraPattern(CameraPattern var1, CallbackWithNoParam var2);

/**
* Whether to lock gimbal while photo taking
* @param var1: indicates whether to lock the gimbal
* @param var2
*/
void lockGimbalWhenTakePhoto(AutelSwitchState var1, CallbackWithNoParam var2);

/**
* Sets the GPS coordinate system
* @param var1: coordinate system WGS84(0),CGCS2000(1),UNKNOWN(-1);
* @param var2
*/
void setGpsCoordinateType(int var1, CallbackWithNoParam var2);

/**
* Obtains the GPS coordinate system
* @param var1
*/
void getGpsCoordinateType(CallbackWithOneParam<Integer> var1);

/**
* Obtains the SD card information
* @param var1
*/
void getSDCardInfo(CallbackWithOneParam<SdCardInternal> var1);

/**
* Obtains the flash memory information
* @param var1
*/
void getFlashCardInfo(CallbackWithOneParam<FlashCardInternal> var1);

/**
* Sets the photo calibration format
* @param mode 0: pix4D, 1: default value
* @param var2
*/
void setCalibrationFormat(int mode, CallbackWithNoParam var2);

/**
* Obtains the photo calibration format
* @param var1
*/
void getCalibrationFormat(CallbackWithOneParam<Integer> var1);

Before taking photos or recording videos, we can use AutelBaseCamera to set camera parameters. The callback functions of the parameter setting API are CallbackWithNoParam and CallbackWithOneParam.

public interface CallbackWithNoParam extends FailedCallback {
void onSuccess();
}
public interface CallbackWithOneParam<T> extends FailedCallback {
void onSuccess(T var1);
}
public interface FailedCallback {
/**
* Invokes this method when call back has failed.
* @param error the error object.
*/
void onFailure(AutelError error);
}

3.3 WorkState Class

WorkState {
//Idle
IDLE("idle", "Idle"),
//Photo taking
CAPTURE("capture", "TakingPhoto"),
//Video recording
RECORD("record", "Recording"),
//Photo taking while video recording
RECORD_PHOTO_TAKING("record_taking", "Recording_taking"),
//Unknown state
UNKNOWN("unknown", "unknown");
}

3.4 CameraPattern

CameraPattern{
MANUAL_FLIGHT(0),//Manual flight
MISSION_FLIGHT(1),//Mission flight
INTELLIGENT_TRACKING(2),//Intelligent tracking (gesture recognition and viewpoint fly)
DELAYED_PHOTOGRAPHY(3),//Time-lapse photography
VISUAL_ORBIT(4),//Orbit fly
PANORAMA(5),//Panorama
MISSION_RECORD(6),//Mission recording
TRAFFIC_POLICE(7),//Traffic police project
SHORT_VIDEO(9),//Short video mode
NIGHT(11), //Night mode
UNKNOWN(-1)
}

Set the camera UI pattern through this API:

 mAutelBaseCamera.setCameraPattern(cameraPattern, new CallbackWithNoParam() {
@Override
public void onSuccess() {
logOut("setCameraPattern onSuccess");
}
@Override
public void onFailure(AutelError error) {
logOut("setCameraPattern fail " + error.getDescription());
}
});

3.5 Set the Supported Camera Mode

You can set the camera mode as needed. The following code example shows how to set the camera mode:

  protected MediaMode mediaMode = MediaMode.SINGLE;
AutelBaseCamera baseCamera = ((CameraActivity) getActivity()).getCurrentCamera();
baseCamera.setMediaMode(mediaMode, new CallbackWithNoParam() {
@Override
public void onFailure(AutelError error) {
logOut("setMediaMode description " + error.getDescription());
}

@Override
public void onSuccess() {
logOut("setMediaMode state onSuccess");
}
});

MediaMode parameter description:

//Single
SINGLE("singal", "Single")
//Video recording
VIDEO("video", "Record")
//Periodic
TIMELAPSE("timelapse", "Timelapse")
//Burst
BURST("burst", "Burst")
//AEB
AEB("aeb", "AEB")
//HDR
HDR("hdr", "HDR")
//MFNR and Night
MFNR("mfnr", "MFNR")
//Time-lapse photography
MOTION_DELAY_SHOT("MotionDelayShot", "MotionDelayShot")
//Unknown work mode
UNKNOWN("unknown", "");

3.6 Start Photo Taking

Before you take photos, you must perform the following checks:

  /**
* Checks whether the camera is in the photo taking mode
*/

MediaMode mode = MediaMode.find(getCameraMode());
if (MediaMode.BURST != mode &&
MediaMode.AEB != mode &&
MediaMode.SINGLE != mode &&
MediaMode.TIMELAPSE != mode) {
//Non-photo taking mode
return;
}

/**
* Checks whether the camera is in idle state
*/
WorkState cameraWorkState = WorkState.find(getWorkStatus());
if (WorkState.IDLE != cameraWorkState) {
//Camera is working
return;
}

/**
* Checks whether the SD card is normal
*/
SDCardState sdCardState = SDCardState.find(getSdCardStatus());
if (sdCardState != SDCardState.CARD_READY && sdCardState != SDCardState.LOW_SPEED_CARD) {
//Abnormal SD card
return;
}

Implement the photo taking functionality:

AutelBaseCamera  baseCamera = ((CameraActivity) getActivity()).getCurrentCamera();
@Override
public void onClick(View v) {
baseCamera.startTakePhoto(new CallbackWithNoParam() {
@Override
public void onFailure(AutelError error) {
logOut("startTakePhoto " + error.getDescription());
}

@Override
public void onSuccess() {
logOut("startTakePhoto onSuccess");
}
});
}
});

3.7 Stop Photo Taking

@Override
public void onClick(View v) {
baseCamera.startTakePhoto(new CallbackWithNoParam() {
@Override
public void onFailure(AutelError error) {
logOut("startTakePhoto " + error.getDescription());
}

@Override
public void onSuccess() {
logOut("startTakePhoto onSuccess");
}
});
}
});

3.8 Start Video Recording

Before you record a video, you must perform the following checks:

/**
* Checks whether the camera is in the video recording mode
*/
MediaMode mode = MediaMode.find(getCameraMode());
if (MediaMode.VIDEO != mode) {
//Non-video recording mode
return;
}
/**
* Checks whether the camera is in idle state
*/
WorkState cameraWorkState = WorkState.find(getWorkStatus());
if (WorkState.IDLE != cameraWorkState) {
//Camera is working
return;
}

/**
* Checks whether the SD card is normal
*/
SDCardState sdCardState = SDCardState.find(getSdCardStatus());
if (sdCardState != SDCardState.CARD_READY && sdCardState != SDCardState.LOW_SPEED_CARD) {
//Abnormal SD card
return;
}

Implementing the video recording functionality:

baseCamera.startRecordVideo(new CallbackWithNoParam() {
@Override
public void onFailure(AutelError error) {
logOut("startRecordVideo " + error.getDescription());
}

@Override
public void onSuccess() {
logOut("startRecordVideo onSuccess");
}
});

3.9 Stop Video Recording

baseCamera.startRecordVideo(new CallbackWithNoParam() {
@Override
public void onFailure(AutelError error) {
logOut("startRecordVideo " + error.getDescription());
}

@Override
public void onSuccess() {
logOut("startRecordVideo onSuccess");
}
});

This is the end of our tutorial on how to use the SDK for implementing photo taking and video recording functionalities. Hope you like this tutorial and continue to learn our next tutorial!