Android
SDK Integration
1. Integrate Tencent Effect SDK. For guidance, refer to Tencent Effect Integration in the integration methods section.
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) { //To restore the previous beauty effect this.elegantPanelView.setPreviousParamList(previousParamList); } this.elegantPanelView.displayView(this); panelLayout.addView(this.elegantPanelView); }
Step Six: Create Beauty Feature
/** * Initialize the beauty filter SDK */ private void initBeautyApi() { TEBeautyKit.create(ThirdBeautyActivity.this.getApplicationContext(), false, new TEBeautyKit.OnInitListener() {@Overridepublic void onInitResult(TEBeautyKit api) {beautyKit = api;beautyKit.setTipsListener(new XmagicApi.XmagicTipsListener() {@Overridepublic void tipsNeedShow(String tips, String tipsIcon, int type, int duration) {showTips(tips, tipsIcon, type, duration);}@Overridepublic void tipsNeedHide(String tips, String tipsIcon, int type) {}});tePanelView.setupWithTEBeautyKit(beautyKit);}}); }
Step Seven: Implementing the Beauty Filter
private void setProcessListener() {//1. Set the `TRTCVideoFrameListener` callback, as outlined in the API documentation {https://liteav.sdk.qcloud.com/doc/api/zh-cn/group__TRTCCloud__android.html#a0b565dc8c77df7fb826f0c45d8ad2d85}mTRTCCloud.setLocalVideoProcessListener(TRTCCloudDef.TRTC_VIDEO_PIXEL_FORMAT_Texture_2D, TRTCCloudDef.TRTC_VIDEO_BUFFER_TYPE_TEXTURE, new TRTCCloudListener.TRTCVideoFrameListener() {@Overridepublic void onGLContextCreated() { //2. GLContext EstablishedLog.e(TAG, "onGLContextCreated");initBeautyApi();}@Overridepublic 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;}@Overridepublic void onGLContextDestory() { //4. GLContext DestructionLog.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() { //4. Dismantling of GLContext Log.e(TAG, "onGLContextDestroy"); if (beautyKit != null) { beautyKit.onDestroy(); } }
Step Nine: Restoring Audio
/** * Employed to restore the sound in stickers * Reactivate the gyroscope sensor, generally called in Activity's onResume method */ public void onResume()
Step Ten: Pausing the sound
/** * Used to pause the sound in stickers * Put the gyroscope sensor on hold, generally called in Activity's onPause method */ public void onPause()
- SDK Integration
- Utilization of SDK
- Step 1: Define the Path
- Step Two: Setting Panel's JSON File
- Step Three: Copying Beauty Resources
- Step 4: Authenticate
- Step 5: Add Panel
- Step Six: Create Beauty Feature
- Step Seven: Implementing the Beauty Filter
- Step Eight: Destroying Beauty Effect Note: Requires destruction in the GL thread
- Step Nine: Restoring Audio
- Step Ten: Pausing the sound