xmagickit module
的 build.gradle
文件找到api 'com.tencent.mediacloud:TencentEffect_S1-04:latest.release'
替换为您购买的 套餐依赖包。
xmagickit module
下的如下目录:../assets/MotionRes
../assets/lut
将 applicationId 修改成与申请的测试授权⼀致的包名。
可参考 Demo ⼯程的 UGCKitVideoRecord 类。
授权:
//鉴权注意事项及错误码详情,请参考 https://www.tencentcloud.com/document/product/1143/45385#.E6.AD.A5.E9.AA.A4.E4.B8.80.EF.BC.9A.E9.89.B4.E6.9D.83
XMagicImpl.checkAuth(new TELicenseCheck.TELicenseCheckListener() {
@Override
public void onLicenseCheckFinish(int errorCode, String msg) {
if (errorCode == TELicenseCheck.ERROR_OK) {
loadXmagicRes();
} else {
Log.e("TAG", "auth fail ,please check auth url and key" + errorCode + " " + msg);
}
}
});
初始化素材:
private void loadXmagicRes() {
if (XMagicImpl.isLoadedRes) {
XmagicResParser.parseRes(mActivity.getApplicationContext());
initXMagic();
return;
}
new Thread(new Runnable() {
@Override
public void run() {
XmagicResParser.copyRes(mActivity.getApplicationContext());
XmagicResParser.parseRes(mActivity.getApplicationContext());
XMagicImpl.isLoadedRes = true;
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
initXMagic();
}
});
}
}).start();
}
短视频和美颜进行绑定:
private void initBeauty() {
TXUGCRecord instance = TXUGCRecord.getInstance(UGCKit.getAppContext());
instance.setVideoProcessListener(new TXUGCRecord.VideoCustomProcessListener() {
@Override
public int onTextureCustomProcess(int textureId, int width, int height) {
if (xmagicState == XMagicImpl.XmagicState.STARTED && mXMagic != null) {
return mXMagic.process(textureId, width, height);
}
return textureId;
}
@Override
public void onDetectFacePoints(float[] floats) {
}
@Override
public void onTextureDestroyed() {
if (Looper.getMainLooper() != Looper.myLooper()) { //非主线程
boolean stopped = xmagicState == XMagicImpl.XmagicState.STOPPED;
if (stopped || xmagicState == XMagicImpl.XmagicState.DESTROYED) {
if (mXMagic != null) {
mXMagic.onDestroy();
}
}
if (xmagicState == XMagicImpl.XmagicState.DESTROYED) {
TXUGCRecord.getInstance(UGCKit.getAppContext()).setVideoProcessListener(null);
}
}
}
});
}
暂停/销毁 SDK:onPause()
用于暂停美颜效果,可以在 Activity/Fragment 生命周期方法中执行,onDestroy 方法需要在 GL 线程调用(可以在 onTextureDestroyed 方法中调用 XMagicImpl 对象的 onDestroy()
) ,更多使用请参考视力中 onTextureDestroyed 方法。
@Override
public void onTextureDestroyed() {
if (Looper.getMainLooper() != Looper.myLooper()) { //非主线程
boolean stopped = xmagicState == XMagicImpl.XmagicState.STOPPED;
if (stopped || xmagicState == XMagicImpl.XmagicState.DESTROYED) {
if (mXMagic != null) {
mXMagic.onDestroy();
}
}
if (xmagicState == XMagicImpl.XmagicState.DESTROYED) {
TXUGCRecord.getInstance(UGCKit.getAppContext()).setVideoProcessListener(null);
}
}
}
布局中添加承载美颜面板的布局:
<RelativeLayout
android:id="@+id/panel_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone"/>
创建美颜对象并添加美颜面板
private void initXMagic() {
if (mXMagic == null) {
mXMagic = new XMagicImpl(mActivity, getBeautyPanel());
} else {
mXMagic.onResume();
}
}
具体操作请参见 Demo ⼯程的 UGCKitVideoRecord类。
本页内容是否解决了您的问题?