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 4: Authenticate
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
private void setProcessListener() {
mTRTCCloud.setLocalVideoProcessListener(TRTCCloudDef.TRTC_VIDEO_PIXEL_FORMAT_Texture_2D, TRTCCloudDef.TRTC_VIDEO_BUFFER_TYPE_TEXTURE, new TRTCCloudListener.TRTCVideoFrameListener() {
@Override
public void onGLContextCreated() {
Log.e(TAG, "onGLContextCreated");
initBeautyApi();
}
@Override
public int onProcessVideoFrame(TRTCCloudDef.TRTCVideoFrame srcFrame, TRTCCloudDef.TRTCVideoFrame 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 onGLContextDestory() {
Log.e(TAG, "onGLContextDestroy");
if (beautyKit != null) {
beautyKit.onDestroy();
beautyKit = null;
}
}
});
}
Step Eight: Destroying Beauty Effect Note: Requires destruction 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?