Use virtual backgrounds
The code on this page only works with the custom UI.
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()
}
MobileRTCMeetingService *meetingService = [[MobileRTC sharedRTC] getMeetingService];
if (meetingService != nil && [meetingService isSupportVirtualBG]) {
[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)
// To list available virtual background
NSArray *listOfVirtualBG = [meetingService getBGImageList];
if (listOfVirtualBG != nil) {
// 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]) {
[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()
}
UIView *previewView = meetingService.previewView;
if (previewView != nil) {
// Preview view is available, add previewView to your UIView
// Start Preview
[meetingService startPreviewWithFrame: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)
/*
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];