Virtual backgrounds
Use ZoomVideoSDKVirtualBackgroundHelper to enable virtual backgrounds. First determine whether the device supports it using isSupportVirtualBackground. If the device supports it, use the helper methods to add, get, set, and remove virtual backgrounds.
Typical flow
To add a virtual background and apply it to your video:
- Use
addVirtualBackgroundItemto add a virtual background item. - Use
getVirtualBackgroundItemListto get a list of available virtual background items. - Choose a virtual background item from the list and use
setVirtualBackgroundItemto set the virtual background.
Use removeVirtualBackgroundItem to remove the virtual background or set the virtual background to None. Use getSelectedVirtualBackgroundItem to get the currently selected background.
Example
This example checks for device support, adds a background from a Bitmap, sets it as the active background, then reads back the current selection and the full list of items.
val vbHelper = ZoomVideoSDK.getInstance().virtualBackgroundHelper
if (vbHelper.isSupportVirtualBackground) {
// Add a background from a Bitmap (for example, decoded from your assets folder)
val newItem = vbHelper.addVirtualBackgroundItem(bitmap)
// Set the new background as the active one
vbHelper.setVirtualBackgroundItem(newItem)
// Later, read or replace the current selection
val selected = vbHelper.selectedVirtualBackgroundItem
val allItems = vbHelper.virtualBackgroundItemList
}
ZoomVideoSDKVirtualBackgroundHelper vbHelper = ZoomVideoSDK.getInstance().getVirtualBackgroundHelper();
if (vbHelper.isSupportVirtualBackground()) {
// Add a background from a Bitmap (for example, decoded from your assets folder)
ZoomVideoSDKVirtualBackgroundItem newItem = vbHelper.addVirtualBackgroundItem(bitmap);
// Set the new background as the active one
vbHelper.setVirtualBackgroundItem(newItem);
// Later, read or replace the current selection
ZoomVideoSDKVirtualBackgroundItem selected = vbHelper.getSelectedVirtualBackgroundItem();
List<ZoomVideoSDKVirtualBackgroundItem> allItems = vbHelper.getVirtualBackgroundItemList();
}
Method reference
The full set of ZoomVideoSDKVirtualBackgroundHelper methods for adding, listing, setting, and removing virtual backgrounds.
// Check if virtual background is supported
fun isSupportVirtualBackground(): Boolean
// Add virtual background item
fun addVirtualBackgroundItem(image: Bitmap): ZoomVideoSDKVirtualBackgroundItem
// Remove virtual background item
fun removeVirtualBackgroundItem(imageItem: ZoomVideoSDKVirtualBackgroundItem): Int
// Get virtual background item list
fun getVirtualBackgroundItemList(): List<ZoomVideoSDKVirtualBackgroundItem>
// Set virtual background item
fun setVirtualBackgroundItem(imageItem: ZoomVideoSDKVirtualBackgroundItem): Int
// Get selected virtual background
fun getSelectedVirtualBackgroundItem(): ZoomVideoSDKVirtualBackgroundItem
// Check if virtual background is supported
boolean isSupportVirtualBackground()
// Add virtual background item
ZoomVideoSDKVirtualBackgroundItem addVirtualBackgroundItem(android.graphics.Bitmap image)
// Remove virtual background item
int removeVirtualBackgroundItem(ZoomVideoSDKVirtualBackgroundItem imageItem)
// Get virtual background item list
List<ZoomVideoSDKVirtualBackgroundItem> getVirtualBackgroundItemList()
// Set virtual background item
int setVirtualBackgroundItem(ZoomVideoSDKVirtualBackgroundItem imageItem)
// Get selected virtual background
ZoomVideoSDKVirtualBackgroundItem getSelectedVirtualBackgroundItem()