The content of this page has been automatically translated by AI. If you encounter any problems while reading, you can view the corresponding content in Chinese.
Help & Documentation>User Generated Short Video SDK

Android

Last updated: 2025-03-17 17:35:52

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'
Replace with the package dependency package you have purchased.
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/MotionRes
Filter: ../assets/lut
3. 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.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);
}
}
});
2. Initialize materials:
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();
}
3. Bind short video and beauty effect:
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()) { //Non-main thread
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);
}
}
}
});
}
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.
@Override
public void onTextureDestroyed() {
if (Looper.getMainLooper()!= Looper.myLooper()) { //Non-main thread
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);
}
}
}
5. Add a layout to host the beauty panel to the layout:
<RelativeLayout
android: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.