Android

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

我的收藏

SDK 集成

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

SDK 使用

第一步:设置路径

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

第二步:设置面板 JSON 文件

请添加您在 TEBeautyKit 集成文档的如何集成下第二步 中添加到您工程中的 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");

第三步:复制美颜资源

将美颜资源复制到 第一步 中设置的路径下,一个版本只需要成功复制一次
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);
}
}); }

第七步:使用美颜

mLivePusher = new V2TXLivePusherImpl(this, V2TXLiveDef.V2TXLiveMode.TXLiveMode_RTC); mLivePusher.enableCustomVideoProcess(true, V2TXLivePixelFormatTexture2D, V2TXLiveBufferTypeTexture); mLivePusher.setObserver(new V2TXLivePusherObserver() { @Override public void onGLContextCreated() { //2. GLContext 创建 Log.d(TAG, "onGLContextCreated"); initBeautyApi(); } @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; } } });

第八步:销毁美颜 注意:需要在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()