Introduction

Camera exposure and focus are commonly used in video calls to enable high-quality video capture. Agora SDK provides a set of camera management methods on the Android platform, with which you can switch between the front and rear camera, set the camera zoom factor, set the exposure region and set the focus position.

  • Camera exposure: Auto exposure is supported where users can maually set the exposure region.
  • Camera focus: Auto face-focus and manual focus are supported.

Implementation

Before proceeding, ensure that you implement a basic video call or live broadcast in your project. See Start a Call/Start a Live Broadcast for details.

Refer to the following steps to set the camera exposure and focus:

  • Exposure
    Call the isCameraExposurePositionSupported method to check whether exposure function is supported. If it is supported, call the setCameraExposurePosition method to set the camera exposure.
    You can monitor the exposure position with the onCameraExposureAreaChanged callback.
  • Auto face-focus
    Call the isCameraAutoFocusFaceModeSupported method to check whether auto face-focus function is supported. If it is supported, call the setCameraAutoFocusModeEnabled method to set the focus.
  • Manual focus
    Call the isCameraFocusSupported method to check whether manual focus function is supported. If it is supported, call the setCameraFocusPositionInPreview method to set the focus.
    You can monitor the focus position with the onCameraFocusAreaChanged callback.

Sample code

// Check whether exposure function is supported and enable exposure.
boolean shouldSetExposure = rtcEngine.isCameraExposurePositionSupported();
if (shouldSetExposure) {
    // Set the camera exposure at (50, 100).
    float positionX = 50.0f;
    float positionY = 100.0f;
    rtcEngine.setCameraExposurePosition(positionX, positionY);
}

// Check whether auto face-focus function is supported and enable auto-face focus.
boolean shouldSetFaceMode = rtcEngine.isCameraAutoFocusFaceModeSupported();
rtcEngine.setCameraAutoFocusFaceModeEnabled(shouldSetFaceMode);

// Check whether manual focus function is supported and set the focus.
boolean shouldManualFocus = rtcEngine.isCameraFocusSupported();
if (shouldManualFocus) {
    // Set the camera focus at (50, 100).
    float positionX = 50.0f;
    float positionY = 100.0f;
    rtcEngine.setCameraFocusPositionInPreview(positionX, positionY);
}

// The camera focus area is updated. You can monitor the update event and implement corresponding logic.
public void onCameraExposureAreaChanged(rect) {
}

// The camera exposure area is updated. You can monitor the update event the implement corresponding logic.
public void onCameraFocusAreaChanged(rect) {
}

API reference