setVirtualBackgroundByIndex method
Future<void>
setVirtualBackgroundByIndex(
- int index
)
Implementation
Future<void> setVirtualBackgroundByIndex(int index) async {
_trtcStreamInfoObs.updateCurrentUnrealBGIndex(index);
final rememberVirtualBackgroundConfig = getConfig().basicConfig?.rememberVirtualBackgroundConfig ?? false;
final unrealBgData = UnrealBgData().bgData[index];
if(unrealBgData == null){
TCICLog.error("unrealBgData is null", actionModule: ActionModule.tcicController.name, actionName: ActionName.setVirtualBackgroundByIndex.name);
return;
}
final bgType = UnrealBgData().bgData[index]!.bgType;
final bgUrl = UnrealBgData().bgData[index]!.bgUrl;
//1 颜色、2 图像、3 虚化
final backgroundType =
bgType == UnrealBgType.path
? 2
: bgType == UnrealBgType.blur
? 3
: 1;
final enable = bgType != UnrealBgType.none;
final absolutePath = await getAbsolutePathFromAsset(bgUrl);
setVirtualBackground(path: absolutePath, backgroundType: backgroundType, blurLevel: 3, color: 0, enable: enable);
try {
if (rememberVirtualBackgroundConfig) {
final virtualBackgroundConfig = {"index": index};
final virtualBackgroundConfigJson = jsonEncode(virtualBackgroundConfig);
sharedPreferences.setString("virtualBackgroundConfig-${_config.userId}", virtualBackgroundConfigJson);
}
} catch (_) {}
}