enableVirtualBackground abstract method
- required bool enabled,
- required VirtualBackgroundSource backgroundSource,
- required SegmentationProperty segproperty,
- MediaSourceType type = MediaSourceType.primaryCameraSource,
Enables/disables virtual background.
The virtual background feature allows replacing the original background of the local user with a static image, dynamic video, blurring the background, or segmenting the portrait from the background to achieve picture-in-picture effects. After successfully enabling the virtual background feature, all users in the channel can see the customized background. Call this method after enableVideo or startPreview. Using video as a virtual background may cause continuous memory usage growth, which can lead to app crashes. Therefore, try to reduce the resolution and frame rate of the video when using it. This feature has high performance requirements. The SDK automatically checks the current device capability when calling this method. It is recommended to use it on devices with the following chipsets: Snapdragon 700 series 750G and above Snapdragon 800 series 835 and above Dimensity 700 series 720 and above Kirin 800 series 810 and above Kirin 900 series 980 and above Devices with A9 and above chips: iPhone 6S and above iPad Air 3rd generation and above iPad 5th generation and above iPad Pro 1st generation and above iPad mini 5th generation and above It is recommended to use this feature under the following conditions: Using a high-definition camera and evenly lit environment. The scene contains few objects, the user's portrait is half-body and mostly unobstructed, and the background color is relatively uniform and different from the user's clothing color. This method depends on the virtual background dynamic library libagora_segmentation_extension.dll. Deleting this library will cause the feature to fail to start properly.
enabledWhether to enable virtual background: true : Enable virtual background. false : Disable virtual background.backgroundSourceThe custom background. See VirtualBackgroundSource. To adapt the resolution of the custom background image to the SDK's video capture resolution, the SDK scales and crops the custom background image while preserving its aspect ratio.segpropertyProcessing properties of the background image. See SegmentationProperty.typeThe media source type to which the effect is applied. See MediaSourceType. In this method, this parameter only supports the following two settings: When using the camera to capture local video, keep the default value primaryCameraSource. To use custom captured video, set this parameter to customVideoSource.
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. See Error Codes for details and resolution suggestions.
Implementation
Future<void> enableVirtualBackground(
{required bool enabled,
required VirtualBackgroundSource backgroundSource,
required SegmentationProperty segproperty,
MediaSourceType type = MediaSourceType.primaryCameraSource});