tencent cloud

Feedback

Last updated: 2024-04-09 11:41:07

    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.
    Refer to MLVB demo project.

    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) { //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() {
    @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() { //2. Creation of GLContext 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() { //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()
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support