Skip to content

Virtual Background

Rohit Sharma edited this page Oct 25, 2021 · 2 revisions

What is Virtual Background?

Virtual Background lets the user use a custom background for the video. Users can set 3 types of virtual background None, Blur, and Custom. Examples of the same are given below:

Virtual Background Type

None

This is a default virtual background type. Setting this type removes the custom/blur background. This is equivalent to disabling virtual background.

Blur

This blurs the background as shown in the image below. To remove this background, you need to set VirtualBackgroundType.NONE.

Custom

This lets the user use their own custom image as background. To remove this background, you need to set VirtualBackgroundType.NONE.

Steps to use Virtual Background

  1. To check if the device supports virtual background

    val isSupported: Boolean = webex.phone.isVirtualBackgroundSupported()
  2. To fetch all the virtual backgrounds available

    webex.phone.fetchVirtualBackgrounds( CompletionHandler { result ->  
        if (result.isSuccessful) {
            val data: List<VirtualBackground>? = result.data
            //display the background
        } else {
            Log.d(tag, "error: ${result.error?.message}")
        }
    })

    This API provides the List of Virtual Backgrounds. None and Blur type VirtualBackground is available by default.

  3. For uploading a virtual background (Max 1280x720)

    val thumbnailFile = FileUtils.getFileFromResource(this, "nature-thumb")
    val file = FileUtils.getFileFromResource(this, "nature")
    val thumbnail = LocalFile.Thumbnail(thumbnailFile, null, 64, 64)
    
    val imgFile = LocalFile(file, null, thumbnail, null)
    
    webex.phone.addVirtualBackground(imgFile, CompletionHandler { result ->
        if (result.isSuccessful) {
            val data: VirtualBackground? = result.data
            //handle the success response
        } else {
            Log.d(tag, "error: ${result.error?.message}")
        }
    })
  4. To apply the virtual background

    //Specify the mode PREVIEW or CALL as per requirement. 
    val mode = Phone.VirtualBackgroundMode.PREVIEW // Phone.VirtualBackgroundMode.CALL
    webex.phone.applyVirtualBackground(virtualBackgroundItem, mode, CompletionHandler { result ->
        if (result.isSuccessful) {
            val data: Boolean? = result.data
            //handle the success response
        } else {
                Log.d(tag, "error: ${result.error?.message}")
        }
    })
  5. To remove the virtual backgrounds

    webex.phone.removeVirtualBackground(background, CompletionHandler { result ->
        if (result.isSuccessful) {
            val data: Boolean? = result.data
            //handle the delete response
        } else {
            Log.d(tag, "error: ${result.error?.message}")
        }
    })

    This API can delete a specific Custom VirtualBackground. None and Blur type cannot be deleted.

  6. You can modify the limit of custom virtual background supported by the setting. The default limit is 3.

    webex.phone.setMaxVirtualBackgroundItems(limit)
  7. To retrieve the limit

    val limit: Int = webex.phone.getMaxVirtualBackgroundItems()

Notes

  • Custom background image types supported are JPG and PNG.
  • SDK will resize uploaded image to 1280x720, if the image size will be greater than 1280x720 to avoid CPU overhead.
  • Storage of application will be increased based on the images uploaded for virtual background
  • Virtual Background uses lots of CPU, once reached threshold limit CallObserver.onCpuHitThreshold will be fired. It is recommended to disable the virtual background feature.
Clone this wiki locally