# Video Management

# Video data collection management

# Set the type of camera to turn on

Before video capture settings, you can get the camera list, current camera, and default camera through the properties and methods in the JCMediaDevice class, as follows:

/**
 * Get camera list
 *
 * @return camera list
 */
public abstract List<JCMediaDeviceCamera> getCameras();

/**
 * Current default camera
 *
 * @return current camera
 */
public abstract JCMediaDeviceCamera getCamera();

/**
 * Default camera
 */
public JCMediaDeviceCamera defaultCamera;

Among them, the camera object (JCMediaDeviceCamera) has the following properties:

/*Camera id*/
public String cameraId;
/*Camera name*/
public String cameraName;
/*Camera type*/
public @CameraType int cameraType;

CameraType(The types of camera) are as follows:

/**
 * The camera is not obtained
 */
public static final int CAMERA_NONE = 0;
/**
 * Front camera
 */
public static final int CAMERA_FRONT = 1;
/**
 * Rear camera
 */
public static final int CAMERA_BACK = 2;
/**
 * Unknown  camera
 */
public static final int CAMERA_UNKNOWN = 3;

After obtaining the camera list, you can call the following method to obtain the camera type in the list:

/**
 * Get camera type
 *
 * @param cameraIndex camera queue index
 * @return camera type
 */
@CameraType
public abstract int getCameraType(int cameraIndex);

If you want to switch the camera, call the following method to switch the specified camera:

/**
 * Switch the camera
 * @param camera camera
 * @return return true/false
 */
public abstract boolean switchCamera(JCMediaDeviceCamera camera);

Sample code:

JCMediaDeviceCamera item = new JCMediaDeviceCamera();
item.cameraType = JCMediaDevice.CAMERA_FRONT;
List<JCMediaDevice.JCMediaDeviceCamera> cameras = mediaDevice.getCameras();
mediaDevice.defaultCamera = cameras.get(0);

# Set camera capture resolution

You can achieve different video resolutions by customizing camera acquisition parameters, such as acquisition height, width, and frame rate.

The camera collection property setting interface is as follows:

/**
 * Set camera collection property
 * @param width     collection width, default 640
 * @param height    collection height, default 360
 * @param frameRate acquisition frame rate, default 30
 */
public abstract void setCameraProperty(int width, int height, int frameRate);

Sample code:

// Set camera collection properties
mediaDevice.setCameraProperty(640, 360, 30);

# Video rendering management

# Create local and remote video images

  • Local video rendering

Local video rendering obtains local video objects for UI interface display by calling the startCameraVideo interface, which opens the camera:

/**
 * Obtain video preview object, and you can get video for UI display through this object
 *
 * @param renderType rendering mode
 * @return              JCMediaDeviceVideoCanvas object
 * @see RenderType
 */
public abstract JCMediaDeviceVideoCanvas startCameraVideo(@RenderType int renderType);

Among them, the rendering mode (JCMediaDeviceRender) has the following three

Name

Description

public static final int RENDER_FULL_SCREEN = 0

Window covering

public static final int RENDER_FULL_CONTENT = 1

The whole image is displayed, there will be black borders, but there will be no black borders when the window is the same as the image ratio

public static final int RENDER_FULL_AUTO = 2

Adaptive

  • Remote video rendering

You can call the startVideo method to get the peer video object and render:

/**
 * Obtain a video object, through which you can obtain video for UI display
 *
 * @param videoSource rendering identifier string, such as renderId in JCMediaChannelParticipant JCCallItem
 * @param renderType rendering mode
 * @return              JCMediaDeviceVideoCanvas object
 * @see RenderType
 */
public abstract JCMediaDeviceVideoCanvas startVideo(String videoSource, @RenderType int renderType);

Sample code:

// Open local video preview
JCMediaDeviceVideoCanvas localCanvas = mediaDevice.startCameraVideo(JCMediaDevice.RENDER_FULL_CONTENT);
viewGroup.addView(localCanvas.getVideoView(), 0);
// Remote video rendering; renderId comes from the call object; one-to-one is JCCallItem object, multi-party is JCMediaChannelParticipant object
JCMediaDeviceVideoCanvas remoteCanvas = mediaDevice.startVideo(renderId, JCMediaDevice.RENDER_FULL_CONTENT);
viewGroup.addView(remoteCanvas.getVideoView(), 0);

# Destroy local and remote video images

At the end of a video call or during a video call, if you want to destroy the video image, you can call the following interface:

/**
 * Stop video
 *
 * @param canvas JCMediaDeviceVideoCanvas object, obtained by startVideo
 */
public abstract void stopVideo(JCMediaDeviceVideoCanvas canvas);

Sample code:

JCMediaDeviceVideoCanvas localCanvas = mediaDevice.startCameraVideo(JCMediaDevice.RENDER_FULL_CONTENT);
JCMediaDeviceVideoCanvas remoteCanvas = mediaDevice.startVideo(renderId, JCMediaDevice.RENDER_FULL_CONTENT);
if (localCanvas != null) {
    mContentView.removeView(localCanvas.getVideoView());
    mediaDevice.stopVideo(localCanvas);
    localCanvas = null;

if (remoteCanvas != null) {
    mContentView.removeView(remoteCanvas.getVideoView());
    mediaDevice.stopVideo(remoteCanvas);
    remoteCanvas = null;
}

# Pause rendering

If you pause the rendering of the screen, you can call the following interface:

/**
 * Pause video rendering
 */
public void pause();

# Resume rendering

If you want to continue rendering the paused picture, you can call the following interface:

/**
 * Continue video rendering
 */
public void resume();

# Video equipment management

Video device management mainly uses the methods in the JCMediaDevice class, as follows:

# Get camera list

/**
 * Get camera list
 *
 * @return camera list
 */
public abstract List<JCMediaDeviceCamera> getCameras();

Sample code:

Get camera list
List<JCMediaDeviceCamera> cameras = mediaDevice.getCameras();

Get the current default camera:

/**
 * Current default camera
 *
 * @return current camera
 */
public abstract JCMediaDeviceCamera getCamera();

Sample code:

Get camera list
JCMediaDeviceCamera camera = mediaDevice.getCamera();

# Turn camera on and off

/**
 * Turn on the camera
 *
 * @return return true/false
 */
public abstract boolean startCamera();

/**
 * Turn off the camera
 *
 * @return return true/false
 */
public abstract boolean stopCamera();

# Switch the camera

/**
 * Switch the camera,SDK will switch the camera according to the current camera type
 *
 * @return return true/false
 */
public abstract boolean switchCamera();

Sample code:

// Turn on the camera
mediaDevice.startCamera();
// Turn off the camera
mediaDevice.stopCamera();
// Switch the camera
mediaDevice.switchCamera();
最后更新时间: 1/17/2023, 5:17:17 PM