Virtual Background
Virtual Background allows users to blur their video background or use images from their library as their video background. This feature works best with a physical green screen in the backdrop or a uniform lighting on a plain backdrop. In other cases, users may experience patchy edges.
Implementing Virtual Background
The virtual background feature is currently supported on the Android platform. It is available in Android SDK v1.0 and later.
Virtual Background SDK
Download Android Virtual Background SDK v1.0
Released: June 1, 2022Follow these steps:
- Download the Android SDK.
- Locate the
.aar
file in the downloaded folder. - Add the
.aar
files under the lib folder. - Go to your application's
build.gradle file
and add the following code in the dependencies section:
implementation 'com.google.mlkit:segmentation-selfie:16.0.0-beta4'implementation 'io.github.zncmn.libyuv:core:0.0.7'implementation fileTree(dir: 'libs', include: ['.aar', '.jar'], exclude: [])
SDK Methods and Callbacks
The EnxVirtualBackground.enableVirtualBackground()
method is used to add virtual background to a local stream. To use this method, create an instance of the EnxVirtualBackground and pass its reference to the
- Method:
enableVirtualBackground(this, enxRoom)
- Class:
EnxVirtualBackground
- Observer:
public void
EnxVirtualBackgroundStateObserver(EnxVirtualBackgroundStateObserverObject)` - Parameters:
-this
: Specifies the self-instance reference.enxRoom
: Specifies the reference of the EnxRoom object.
- Callbacks:
onAttachVirtualBackground
: When virtual background is attached to the specified local stream.onDetachVirtualBackground
: When virtual background is detached from the specified local stream.onVirtualBackgroundFailure
: When virtual background fails to attach with the specified local stream.
Example:
// Initiate Object of EnxVirtualBackgroundEnxVirtualBackground virtualBackground = new EnxVirtualBackground();// Enable Virtual BackgroundvirtualBackground.enableVirtualBackground(this, enxRoom);// Set ObservervirtualBackground.SetEnxVirtualBackgroundStateObserver(this);// Callback when Virtual Background is attached to the Local Stream.@Overridepublic void onAttachVirtualBackground(JSONObject jsonObject) {}// Callback when Virtual Background is detached from the Local Stream.@Overridepublic void onDetachVirtualBackground(JSONObject jsonObject) {}// Callback when Virtual Background fails to attach with Local Stream.@Overridepublic void onVirtualBackgroundFailure(JSONObject jsonObject) {}