enableVirtualBackground abstract method

Future<void> enableVirtualBackground({
  1. required bool enabled,
  2. required VirtualBackgroundSource backgroundSource,
  3. required SegmentationProperty segproperty,
  4. MediaSourceType type = MediaSourceType.primaryCameraSource,
})

Enables/Disables the virtual background.

The virtual background feature enables the local user to replace their original background with a static image, dynamic video, blurred background, or portrait-background segmentation to achieve picture-in-picture effect. Once the virtual background feature is enabled, all users in the channel can see the custom background. Call this method after calling enableVideo or startPreview. This feature has high requirements on device performance. When calling this method, the SDK automatically checks the capabilities of the current device. Agora recommends you use virtual background on devices with the following processors: Snapdragon 700 series 750G and later Snapdragon 800 series 835 and later Dimensity 700 series 720 and later Kirin 800 series 810 and later Kirin 900 series 980 and later Devices with an A9 chip and better, as follows: iPhone 6S and later iPad Air 3rd generation and later iPad 5th generation and later iPad Pro 1st generation and later iPad mini 5th generation and later Agora recommends that you use this feature in scenarios that meet the following conditions: A high-definition camera device is used, and the environment is uniformly lit. There are few objects in the captured video. Portraits are half-length and unobstructed. Ensure that the background is a solid color that is different from the color of the user's clothing. This method relies on the virtual background dynamic library libagora_segmentation_extension.dll. If the dynamic library is deleted, the function cannot be enabled normally.

  • enabled Whether to enable virtual background: true : Enable virtual background. false : Disable virtual background.
  • backgroundSource The custom background. See VirtualBackgroundSource. To adapt the resolution of the custom background image to that of the video captured by the SDK, the SDK scales and crops the custom background image while ensuring that the content of the custom background image is not distorted.
  • segproperty Processing properties for background images. See SegmentationProperty.
  • type The type of the video source. See MediaSourceType. In this method, this parameter supports only the following two settings: The default value is primaryCameraSource. If you want to use the second camera to capture video, set this parameter to secondaryCameraSource.

Returns When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly.

Implementation

Future<void> enableVirtualBackground(
    {required bool enabled,
    required VirtualBackgroundSource backgroundSource,
    required SegmentationProperty segproperty,
    MediaSourceType type = MediaSourceType.primaryCameraSource});