Step 1: Decompress the Demo Project
1. Download the UGSV Demo project integrated with Tencent Effect TE. This Demo is built based on Tencent special effect SDK S1 - 04 package.
2. Replace resources: Since the SDK package used in this Demo project may not match your actual package, replace the relevant SDK files in this Demo with the SDK files of your actual used package. Specific operations are as follows:
Find in the
build.gradle file of xmagickit module.api 'com.tencent.mediacloud:TencentEffect_S1-04:latest.release'
If your package includes animation and filter features, then you need to download the corresponding resources on the Tencent special effect SDK Download Page, and place the animation and filter materials in the following directory under
xmagickit module:Animation effects:
../assets/MotionResFilter:
../assets/lut3. Introduce the xmagickit module in the Demo project into the actual project.
Step Two: Open the build.gradle of the app Module
Change applicationId to the package name consistent with the applied trial authorization.
Step Three: SDK API Integration
Refer to the UGCKitVideoRecord class in the Demo project.
1. Authorization:
//For authentication precautions and error code details, please refer to https://cloud.tencent.com/document/product/616/65891#.E6.AD.A5.E9.AA.A4.E4.B8.80.EF.BC.9A.E9.89.B4.E6.9D.83XMagicImpl.checkAuth(new TELicenseCheck.TELicenseCheckListener() {@Overridepublic 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);}}});
2. Initialize materials:
private void loadXmagicRes() {if (XMagicImpl.isLoadedRes) {XmagicResParser.parseRes(mActivity.getApplicationContext());initXMagic();return;}new Thread(new Runnable() {@Overridepublic void run() {XmagicResParser.copyRes(mActivity.getApplicationContext());XmagicResParser.parseRes(mActivity.getApplicationContext());XMagicImpl.isLoadedRes = true;new Handler(Looper.getMainLooper()).post(new Runnable() {@Overridepublic void run() {initXMagic();}});}}).start();}
3. Bind short video and beauty effect:
private void initBeauty() {TXUGCRecord instance = TXUGCRecord.getInstance(UGCKit.getAppContext());instance.setVideoProcessListener(new TXUGCRecord.VideoCustomProcessListener() {@Overridepublic int onTextureCustomProcess(int textureId, int width, int height) {if (xmagicState == XMagicImpl.XmagicState.STARTED && mXMagic != null) {return mXMagic.process(textureId, width, height);}return textureId;}@Overridepublic void onDetectFacePoints(float[] floats) {}@Overridepublic void onTextureDestroyed() {if (Looper.getMainLooper()!= Looper.myLooper()) { //Non-main threadboolean 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);}}}});}
4. Suspend/Terminate SDK:
onPause() is used to suspend the beauty effect and can be executed in the Activity/Fragment lifecycle methods. The onDestroy method needs to be called on the GL thread (you can call the onDestroy() of the XMagicImpl object in the onTextureDestroyed method). For more usage, see the onTextureDestroyed method in the example.@Overridepublic void onTextureDestroyed() {if (Looper.getMainLooper()!= Looper.myLooper()) { //Non-main threadboolean 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);}}}
5. Add a layout to host the beauty panel to the layout:
<RelativeLayoutandroid:id="@+id/panel_layout"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:visibility="gone"/>
6. Create a Beauty Object and add a beauty panel
private void initXMagic() {if (mXMagic == null) {mXMagic = new XMagicImpl(mActivity, getBeautyPanel());} else {mXMagic.onResume();}}
For specific operations, see the UGCKitVideoRecord class in the Demo project.