Android

最近更新时间:2024-04-09 11:38:51

我的收藏

SDK 集成

1. 集成腾讯特效SDK,请参考 独立集成腾讯特效 中的集成方式。
2. 集成TEBeautyKit库,请参考 TEBeautyKit / Android 中的如何集成模块。
可参考 TRTC demo工程。

SDK 使用

第一步:设置路径

TEBeautyKit.setResPath((new File(getFilesDir(), "xmagic_dir").getAbsolutePath()));

第二步:设置面板 JSON 文件

请添加您在TEBeautyKit集成文档的1.2模块中添加到您工程中的JSON文件的路径,没有的JSON文件则将路径设置为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");

第三步:复制美颜资源

将美颜资源复制到2.1中设置的路径下,一个版本只需要成功复制一次
new Thread(() -> { boolean result = TEBeautyKit.copyRes(MainActivity.this.getApplicationContext()); runOnUiThread(() -> { if (result) { saveCopyData(); } teProgressDialog.dismiss(); checkLicense(); }); }).start();

第四步:鉴权

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 "); } });

第五步:添加面板

private void initBeautyPanelView() { RelativeLayout panelLayout = findViewById(R.id.live_pusher_bp_beauty_panel); this.tePanelView = new TEPanelView(this); if (lastParamList != null) { //用于恢复美颜上次效果 this.tePanelView.setLastParamList(lastParamList); } this.tePanelView.showView(this); panelLayout.addView(this.tePanelView); }

第六步:创建美颜

/** * 初始化美颜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);
}
}); }

第七步:使用美颜

private void setProcessListener() {
//1. 设置 TRTCVideoFrameListener 回调, 详见API说明文档 {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() {
@Override
public void onGLContextCreated() { //2. GLContext 创建
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() { //4. GLContext 销毁
Log.e(TAG, "onGLContextDestroy");
if (beautyKit != null) {
beautyKit.onDestroy();
beautyKit = null;
}
}
});
}

第八步:销毁美颜 注意:需要在GL线程销毁

public void onGLContextDestory() { //4. GLContext 销毁 Log.e(TAG, "onGLContextDestroy"); if (beautyKit != null) { beautyKit.onDestroy(); } }

第九步:恢复声音

/** * 用于恢复贴纸中的声音 * 恢复陀螺仪传感器,一般在Activity的onResume方法中调用 */ public void onResume()

第十步:暂停声音

/** * 用于暂停贴纸中的声音 * 暂停陀螺仪传感器,一般在Activity的onPause方法中调用 */ public void onPause()