SDK Integration
2. To integrate the TEBeautyKit library, please consider TEBeautyKit / Android on how to integrate modules. Utilization of SDK
Step 1: Define the Path
TEBeautyKit.setResPath((new File(getFilesDir(), "xmagic_dir").getAbsolutePath()));
Step Two: Setting Panel's JSON File
Please append the path of the JSON file added to your project in the second step of the 'How to Integrate' section in the TEBeautyKit Integration Document. If there is no JSON file, then the path Setting should be null. TEUIConfig.getInstance().setTEPanelViewRes("beauty_panel/beauty.json",null, "beauty_panel/lut.json", "beauty_panel/motions.json", "beauty_panel/makeup.json", "beauty_panel/segmentation.json");
Step Three: Copying Beauty Resources
Copy the beauty resources to the path under Step One in Setting, one version only needs to be copied successfully once. new Thread(() -> {
boolean result = TEBeautyKit.copyRes(MainActivity.this.getApplicationContext());
runOnUiThread(() -> {
if (result) {
saveCopyData();
}
teProgressDialog.dismiss();
checkLicense();
});
}).start();
Step Four: Authentication
TEBeautyKit.setTELicense(this.getApplicationContext(),LicenseConstant.mXMagicLicenceUrl,LicenseConstant.mXMagicKey, (i, s) -> {
if (i == LicenseConstant.AUTH_STATE_SUCCEED) {
Intent intent = new Intent(MainActivity.this, ThirdBeautyActivity.class);
startActivity(intent);
} else {
Log.e(TAG, "te license check is failed,please checke ");
}
});
Step 5: Add Panel
private void initializeBeautyPanelView() {
RelativeLayout panelLayout = findViewById(R.id.live_pusher_bp_beauty_panel);
this.elegantPanelView = new TEPanelView(this);
if (previousParamList != null) {
this.elegantPanelView.setPreviousParamList(previousParamList);
}
this.elegantPanelView.displayView(this);
panelLayout.addView(this.elegantPanelView);
}
Step Six: Create Beauty Feature
private void initBeautyApi() {
TEBeautyKit.create(ThirdBeautyActivity.this.getApplicationContext(), false, new TEBeautyKit.OnInitListener() {
@Override
public void onInitResult(TEBeautyKit api) {
beautyKit = api;
beautyKit.setTipsListener(new XmagicApi.XmagicTipsListener() {
@Override
public void tipsNeedShow(String tips, String tipsIcon, int type, int duration) {
showTips(tips, tipsIcon, type, duration);
}
@Override
public void tipsNeedHide(String tips, String tipsIcon, int type) {
}
});
tePanelView.setupWithTEBeautyKit(beautyKit);
}
});
}
Step Seven: Implementing the Beauty Filter
mLivePusher = new V2TXLivePusherImpl(this, V2TXLiveDef.V2TXLiveMode.TXLiveMode_RTC);
mLivePusher.enableCustomVideoProcess(true, V2TXLivePixelFormatTexture2D, V2TXLiveBufferTypeTexture);
mLivePusher.setObserver(new V2TXLivePusherObserver() {
@Override
public void onGLContextCreated() {
Log.d(TAG, "onGLContextCreated");
initializeBeautyApi();
}
@Override
public int onProcessVideoFrame(V2TXLiveDef.V2TXLiveVideoFrame srcFrame, V2TXLiveDef.V2TXLiveVideoFrame dstFrame) {
if (beautyKit != null) {
dstFrame.texture.textureId = beautyKit.process(srcFrame.texture.textureId, srcFrame.width, srcFrame.height);
}else {
dstFrame.texture.textureId = srcFrame.texture.textureId;
}
return 0;
}
@Override
public void onGLContextDestroyed() {
Log.d(TAG, "onGLContextDestroyed");
if (beautyKit != null) {
beautyKit.onDestroy();
beautyKit = null;
}
}
});
Step Eight: Dismantling the Beauty Filter Note: It needs to be dismantled in the GL thread
public void onGLContextDestory() {
Log.e(TAG, "onGLContextDestroy");
if (beautyKit != null) {
beautyKit.onDestroy();
}
}
Step Nine: Restoring Audio
Step Ten: Pausing the sound
Was this page helpful?