Camera and Gimbal

Overview

If you find any problems or bugs when you are using the tutorials, please submit a issue in the github to inform us. We are glad to receive any pull request from the Github, and help you to repair those issues.

Camera

Camera class of SDK provides the functionality of taking pictures and videos. To get callbacks of click events, register to the Camera.ResultListener. This listener provides callbacks to indicate if clicking picture/video was successful or unsuccessful.

The following code snippet demonstrates how to use Camera class in the SDK, to click pictures in just one line of code. 


Camera.asyncTakePhoto ( );

Before calling the above method, make sure you set the camera mode to PHOTO. This can be done using the following function. This method is defined in Camera class in the SDK.


setMode(Camera.Mode mode, Camera.ModeListener listener)

The following code snippet demonstrates how to register to the camera mode listener and result listener, so that we can notify users if the mode change/capture picture was successful or not.


//Camera Mode Listener
public static void registerCameraModeListener(Context context) {
    Camera.ModeListener cameraModeListener = new Camera.ModeListener() {
           @Override
           public void callback(Camera.Result result, Camera.Mode mode) {
                //Perform action based on the result
                Log.d(TAG, mode + " mode set " + result.resultStr);
           }
       };
    }

//Camera Result Listener
public static void registerCameraResultListener ( )
   {
      Camera.ResultListener cameraResultListener = new Camera.ResultListener ( )
         {
            @Override
            public void resultCallback ( Camera.Result result )
            {
               // Handle result
               Log.d ( TAG, result.resultStr );
            }

         };
         Camera.setResultListener ( cameraResultListener );
   }

This example only demonstrates how to capture a picture. To achieve other functions, such as recording video, camera settings and taking photos in specific intervals, please refer the API documentation.

Gimbal

The Gimbal is used to keep the camera stable and control the angle of camera. Using the features exposed by the Gimbal class in the SDK, you can rotate the camera clockwise or anti-clockwise, move the camera up or down and pan the camera. 

The follow code snippet demonstrates how to use the Gimbal class, to control the angle of the camera.


Gimbal.asyncSetPitchAndYawOfJni ( pitch, yaw, GimbalListener.getGimbaListener ( ) );

With this one line of code, you can set the angle of the camera required. You also pass a gimbal listener to this method, to know if the action was successful or unsuccessful. The following code snippet shows how to register to a Gimbal listener.


public static Gimbal.ResultListener getGimbaListener ( )
	 {
	    gimbalResultListener = new Gimbal.ResultListener ( )
		{
		  @Override
		   public void onResultCallback ( Gimbal.Result result ) {
                         // Handle result
			 Log.d ( TAG, result.resultStr );
		   }
		};
			return gimbalResultListener;
	 }

Please check the API documentation for more details regarding the Camera and Gimbal features supported by the SDK.