如何运行 Demo
1. 下载 Demo,并解压。
2. 使用 Android Studio 打开项目
LiteAVDemo(UGC)。3. 在
xiaoshipindemo 模块下找到 LicenseManager 类,填写申请的短视频 License 和腾讯特效 License 信息:ugcLicenceUrl / ugcKey:短视频 License 的授权地址与密钥;xmagicAuthLicenceUrl / xmagicAuthKey:腾讯特效 License 的授权地址与密钥。œ4. 在
app 模块下找到 build.gradle 文件,将 applicationId 的值修改为申请 License 时填写的 Android 包名。SDK 集成
1. 集成美颜特效
集成 SDK
集成素材
2. 集成 TEBeautyKit
添加面板 JSON 文件(如果不使用默认面板可以不添加)
SDK 使用
第一步:设置面板 JSON 文件
第二步:设置资源存放路径并复制资源
//下边是TEBeautySDKManger.java中的代码片段TEBeautyKit.setResPath(new File(applicationContext.getFilesDir(), "ugc_xmagic").getAbsolutePath());TEBeautyKit.copyRes(applicationContext); //此方法是耗时操作,需要在子线程执行
第三步:鉴权
需要在创建美颜之前完成鉴权操作。
//下边是TEBeautySDKManger.java中的代码片段TEBeautyKit.setTELicense(applicationContext, xmagicAuthLicenceUrl, xmagicAuthKey, listener);
第四步:创建美颜对象并设置进面板中
private void initTEBeautyKit() {mBeautyKit = new TEBeautyKit(getContext().getApplicationContext(), XmagicConstant.EffectMode.PRO);mCustomPropertyManager.setBeautyKit(mBeautyKit);mPanelView.setupWithTEBeautyKit(mBeautyKit); //将美颜对象设置给面板中,这样在操作面板的时候就能调整美颜属性}
第五步:在录制页面添加美颜处理
private void registerVideoProcessListener() {TXUGCRecord instance = TXUGCRecord.getInstance(UGCKit.getAppContext());instance.setVideoProcessListener(new TXUGCRecord.VideoCustomProcessListener() {@Overridepublic int onTextureCustomProcess(int textureId, int width, int height) {if (mBeautyType == 1 && mBeautyKit != null) {return mBeautyKit.process(textureId, width, height);}return textureId;}@Overridepublic void onDetectFacePoints(float[] floats) {}@Overridepublic void onTextureDestroyed() {if (Looper.getMainLooper() != Looper.myLooper()) { //非主线程mCustomPropertyManager.setBeautyKit(null);if (mBeautyKit != null) {mLastParamList = mBeautyKit.exportInUseSDKParam();mBeautyKit.onDestroy();}mIsTextureDestroyed = true;unRegisterVideoProcessListener();}}});}
第六步:销毁美颜
在第五步中的 onTextureDestroyed 方法中对美颜对象进行销毁。
public void onTextureDestroyed() {if (Looper.getMainLooper() != Looper.myLooper()) { //非主线程mCustomPropertyManager.setBeautyKit(null);if (mBeautyKit != null) {mLastParamList = mBeautyKit.exportInUseSDKParam(); //导出美颜参数mBeautyKit.onDestroy(); //销毁美颜}mIsTextureDestroyed = true;unRegisterVideoProcessListener();}}
第七步:恢复声音
/*** 用于恢复贴纸中的声音* 恢复陀螺仪传感器,一般在Activity的onResume方法中调用*/this.mBeautyKit.onResume()
第八步:暂停声音
/*** 用于暂停贴纸中的声音* 暂停陀螺仪传感器,一般在Activity的onPause方法中调用*/this.mBeautyKit.onPause()
详细调用请参见 Demo 工程的 UGCKitVideoRecord 类。