Virtual Background Plugin

Introduction

The Virtual Background Plugin helps in blurring or adding an image as the background of a video frame. This guide provides an overview of usage of the Virtual Background Plugin of 100ms.

Supported Versions/Resolutions

  • Minimum 100ms SDK version it can work with is 2.9.58
  • Minimum 100ms Room Kit version it can work with is 1.2.18
  • Has poor fps on older android phones

Add dependency

If not using room kit:

Adding the Virtual Background plugin and SDK dependency to your app-level build.gradle.

build.gradle
dependencies { // See the version in the badge above. def hmsVersion = "x.x.x" implementation "live.100ms:android-sdk:$hmsVersion" // Essential implementation "live.100ms:virtual-background:$hmsVersion" }

In Prebuilt/RoomKit

Enable it from the dashboard, go to Customize Prebuilt -> Screens and Components -> (scroll down the left pane) Virtual Background.

How to Integrate Virtual Background Plugin:

Instantiate

💡On instantiating Virtual Background Plugin

Always call addPlugin() after onJoin() from hmsSDK.join() or onPreview() from hmsSDK.preview().
The loading takes a while and if this is unacceptable, you can call addPlugin before join but no onSuccess or onError callbacks will be fired until after join succeds so don't wait for them.

val hmsSDK = HMSSDK .Builder(application) .build() val virtualBackGroundPlugin by lazy { HMSVirtualBackground(hmsSDK) } //call this after onJoin() or after onPreview() fun addVirtualBackgroundPlugin() { if (hmsSDK.getLocalPeer()?.videoTrack != null) { hmsSDK.addPlugin(virtualBackGroundPlugin, object : HMSActionResultListener { override fun onError(error: HMSException) {} override fun onSuccess() { } }) } }
💡On instantiating Virtual Background Plugin

This is a async operation. It takes a few seconds on some devices to start. You can add a UI loader on onSuccess() callback

Now let's take a look at the method signature of HMSVirtualBackground.

Enable Blur Background

Enable the blur background functionality using the following method. You can optionally pass blur percentage ranging from 0-100

virtualBackgroundPlugin.enableBlur()

Enable Image Background

Enable the background image functionality by providing a bitmap image:

virtualBackgroundPlugin.enableBackground(bitmap: Bitmap)

Get Blur Percentage

Gets blur percentage of a non-person in a video frame. Value is between 0 to 100 default is 75.

virtualBackgroundPlugin.getCurrentBlurPercentage()

Remove/Detach Virtual Background Plugin

To remove/detach video plugin at runtime:

hmsSDK.removePlugin(virtualBackgroundPlugin, object : HMSActionResultListener { override fun onError(error: HMSException) {} override fun onSuccess() {} })

Have a suggestion? Recommend changes ->

Was this helpful?

1234