Use virtual backgrounds

View as Markdown

Use isSupportVirtualBG in MobileRTCMeetingService to determine whether the device supports virtual backgrounds, then use MobileRTCMeetingService to enable them. You can also check to see if the smart virtual background - virtual backgrounds with green screens - are supported.

if let meetingService = MobileRTC.shared().getMeetingService(), meetingService.isSupportVirtualBG() {
    // Virtual background is supported

    // Check if smart virtual background is supported
    meetingService.isDeviceSupportSmartVirtualBG()
}

If the device supports virtual backgrounds, use meetingService to list, add, remove, and set virtual backgrounds.

// To list available virtual background
if let listOfVirtualBG:[MobileRTCVirtualBGImageInfo] = meetingService.getBGImageList() {
    // This list will contained a NONE, BLUR or Item (self added) virtual background type.
    // The MobileRTCVirtualBGImageInfo has a isSelect property to indicate if the current virtual background is selected.
}

// To add virtual background to list, first check if have permission to add
if meetingService.isAllowToAddNewVBItem() {
    let error = meetingService.addBGImage(UIImage)
}

/*
 To remove a specific virtual background from the list.
 Note: You cannot remove NONE and BLUR type.
 */
meetingService.removeBGImage(MobileRTCVirtualBGImageInfo)

// To set a specific virtual background
meetingService.useBGImage(MobileRTCVirtualBGImageInfo)

Users can preview the virtual background.

if let previewView: UIView = meetingService.previewView {
    // Preview view is available, add previewView to your UIView

    // Start Preview
    meetingService.startPreview(withFrame: CGRect)

    // Stop Preview
    meetingService.stopPreview()
}

Users can also have green screen support for virtual backgrounds, but this functionality is only available for iPads.

/*
 For green background, there are these 3 methods available
 Note: Only iPad support virtual background green screen, iPhone does not support this feature.
 */
meetingService.isUsingGreenVB()
meetingService.enableGreenVB(Bool)
meetingService.selectGreenVBPoint(CGPoint)