VideoCanvas

Used to set the display, rendering, and layout properties of the video canvas.

public class VideoCanvas {
  public int uid;
  public int subviewUid;
  public static final int RENDER_MODE_HIDDEN = 1;
  public static final int RENDER_MODE_FIT = 2;
  public static final int RENDER_MODE_ADAPTIVE = 3;
  public static final int VIEW_SETUP_MODE_REPLACE = 0;
  public static final int VIEW_SETUP_MODE_ADD = 1;
  public static final int VIEW_SETUP_MODE_REMOVE = 2;
  public View view;
  public SurfaceTexture surfaceTexture;
  public int renderMode;
  public int mirrorMode;
  public int setupMode = VIEW_SETUP_MODE_REPLACE;
  public int sourceType;
  public int mediaPlayerId;
  public Rect rect;
  public boolean enableAlphaMask;
  public int backgroundColor;
  public Constants.VideoModulePosition position = Constants.VideoModulePosition.VIDEO_MODULE_POSITION_POST_CAPTURER;
}

Properties

uid
User ID of the published video source.
subviewUid
User ID of the specific sub-video stream in a composite video stream.
RENDER_MODE_HIDDEN
Hidden mode: Scales the video proportionally until the view is filled (some parts of the video may be cropped).
RENDER_MODE_FIT
Fit mode: Scales the video proportionally until one dimension fits the view boundary, with black padding for the remaining area.
RENDER_MODE_ADAPTIVE
Adaptive mode. This mode is deprecated and not recommended by Agora.
VIEW_SETUP_MODE_REPLACE
Sets the view mode to replace mode, which is the default value.
VIEW_SETUP_MODE_ADD
Sets the view mode to add a new view.
VIEW_SETUP_MODE_REMOVE
Sets the view mode to remove a view.
view
The view window used to display the video. Must be of type SurfaceView or TextureView.
Note: Only one of view or surfaceTexture can be set in a VideoCanvas. If both are set, only view takes effect.
surfaceTexture
The container that provides the video image.
Note: Only one of view or surfaceTexture can be set in a VideoCanvas. If both are set, only view takes effect.
renderMode
Rendering mode:
  • RENDER_MODE_HIDDEN (1): Hidden mode.
  • RENDER_MODE_FIT (2): Fit mode.
  • RENDER_MODE_ADAPTIVE (3): Adaptive mode (deprecated and not recommended by Agora).
mirrorMode
Note:
  • Local video view mirror mode: enabled by default when using the front camera, disabled by default when using the rear camera.
  • Mirror mode is disabled by default for remote users.
Mirror mode:
  • VIDEO_MIRROR_MODE_AUTO (0): SDK automatically determines whether to enable mirror mode.
  • VIDEO_MIRROR_MODE_ENABLED (1): Enables mirror mode for local view.
  • VIDEO_MIRROR_MODE_DISABLED (2): Disables mirror mode for local view.
setupMode
Note: It is recommended to set setupMode to VIEW_SETUP_MODE_REMOVE when the view is no longer used to prevent rendering resource leaks.
View setup mode:
  • VIEW_SETUP_MODE_REPLACE (0): Replace view, default value.
  • VIEW_SETUP_MODE_ADD (1): Add view.
  • VIEW_SETUP_MODE_REMOVE (2): Remove view.
sourceType
Type of video source. See VideoSourceType.
mediaPlayerId
ID of the media player.
rect
Display area of the video frame. width and height indicate the pixel dimensions of the video in this area. Default is null (width or height is 0), which means the actual resolution of the video frame is displayed. See Rect.
enableAlphaMask
Whether to enable alpha mask rendering:
  • true: Enable.
  • false: Disable.
This feature enables transparent image effects, such as extracting portraits from video and combining with other features to achieve picture-in-picture, watermarking, etc.
backgroundColor
Background color of the video canvas in RGBA format. Default is 0x00000000, which indicates black.
Note:
  • If you are developing with Kotlin and encounter a compilation error when setting it to 0xFFFFFFFF, use (0xFFFFFFFF).toInt() or android.graphics.Color.parseColor("#FFFFFFFF").
  • Alpha channel is not supported when using RGBA format.
position
Observation position of the video frame in the video pipeline. See VideoModulePosition.