tencent cloud

User Generated Short Video SDK

Android

Download
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-05-11 17:50:34
This document explains how to quickly integrate the TAVMagicUIKit SDK and build a full-featured Premium UGSV experience with built-in UI components.

TAVEditorUIKit Component

TAVEditorUIKit is a highly integrated, full-featured UI component suite for video editing.

Integration Steps

1. Add the UIKit dependency to the project's build.gradle file.
implementation 'com.yunxiao.tavmagic:tavmagicuikit:x.x.x'
2. Add TAVEditorUIKit to the layout.
<com.yunxiao.tavmagic.uikit.TAVEditorUIKit
android:id="@+id/editor_ui"
android:layout_width="match_parent"
android:layout_height="match_parent" />
3. Initialize the editor.
TAVEditorUIKit editor = findViewById(R.id.editor_ui);

// Initialization Method 1: Use a list of video paths
List<String> videoPaths = Arrays.asList("path1.mp4", "path2.mp4");
editor.initWithClipPath(videoPaths);

// Initialization Method 2: Use a draft
TAVDraft draft = loadDraft();
editor.initWithDraft(draft);
4. Handle the lifecycle.
@Override
protected void onResume() {
super.onResume();
editor.onResume(true); // true indicates that playback will resume.
}

@Override
protected void onPause() {
super.onPause();
editor.onPause();
}

@Override
protected void onDestroy() {
super.onDestroy();
editor.onDestroy();
}

@Override
public void onBackPressed() {
if (!editor.onBackPressed()) {
super.onBackPressed();
}
}
5. Configure the required permission provider.
// Set Permission Provider
editor.setPermissionProvider(new ITAVPermissionProvider() {
@Override
public boolean checkPermission(String permission) {
return ContextCompat.checkSelfPermission(MainActivity.this, permission)
== PackageManager.PERMISSION_GRANTED;
}
@Override
public void requestPermission(String permission, TAVConsumer<Boolean> callback) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{permission}, REQUEST_CODE);
}
});

UI Scaling For Different Screen Sizes

The TAVMagicUIKit SDK provides a built-in UI scaling solution for different screen sizes. To use it, simply make the Activity that hosts UIKit extend TAVMagicAdaptActivity. If your app already has a custom BaseActivity, you can copy the following code into the Activity that hosts UIKit.
Note:
This scaling logic affects only the Activity where it is applied.
public class TAVMagicAdaptActivity extends AppCompatActivity {
private static final String TAG = "TAVMagicAdaptActivity";
private static final float TARGET_WIDTH_DP = 375;
private Context mCustomCtx;

@Override
protected void attachBaseContext(Context newBase) {
if (mCustomCtx == null) {
mCustomCtx = createCustomContext(newBase);
}
super.attachBaseContext(mCustomCtx);
}

private Context createCustomContext(Context context) {
final DisplayMetrics systemDM = Resources.getSystem().getDisplayMetrics();
final DisplayMetrics activityDM = context.getResources().getDisplayMetrics();
float targetDensity = activityDM.widthPixels / TARGET_WIDTH_DP;
float targetScaledDensity = targetDensity * (systemDM.scaledDensity / systemDM.density);
Configuration newConfig = new Configuration(context.getResources().getConfiguration());
Context adaptedContext = context.createConfigurationContext(newConfig);
DisplayMetrics newMetrics = adaptedContext.getResources().getDisplayMetrics();
newMetrics.density = targetDensity;
newMetrics.scaledDensity = targetScaledDensity;
return adaptedContext;
}

@Override
public Resources getResources() {
return (mCustomCtx != null && mCustomCtx.getResources() != null)
? mCustomCtx.getResources() : super.getResources();
}
}

Cover Selector

The TAVMagicUIKit SDK provides a built-in cover selector that allows users to choose any frame from the edited video as the cover.

Launch Configuration

TAVCoverRequest

Description
A request model for cover generation. It is used to describe the context of a cover generation/frame capture request, including the source context (an editor instance or draft), the target timestamp, placeholder image, maximum duration limit, and render resolution level.
Parameters
Field Name
Type
Description
editorKey
String
The unique key of the corresponding editor instance, used to generate a cover from the current editor session.
draft
TAVDraft
The draft object, used when generating a cover offline from a draft.
position
long
The initial video timestamp to display when launching the cover selector, in microseconds (us).
coverPlaceHolder
String
The file path of the cover placeholder image (optional), used to display a placeholder image before the final cover is generated.
maxDuration
long
The maximum video duration for the current request, in microseconds (us). It is used to limit the selectable duration range in the cover selector.
renderSizeLevel
int
The render resolution level. The default value is TAVEditorConstants.VIDEO_LEVEL_720P.

Cover Result

TAVCoverResult

Description
A result model for cover generation or selection. It is used to describe the cover thumbnail information for a specific timestamp, including the timestamp and the local cache path.
Parameters
Field Name
Type
Description
position
long
The video timestamp corresponding to the cover, in microseconds (us).
thumbPath
String
The local cache file path of the cover image.

Integration Steps

1. The cover selector supports two launch modes.
Launch from the current editor instance. An offscreen editor instance is forked from TAVEditorUIKit for export or cover selection.
String editorKey = mViewBinding.uiKit.forkOffscreenEditor();
Launch the cover selector from a draft. Create a TAVDraft object from the local draft path.
TAVDraft draft = TAVDraft.createFromJsonPath(draftDir + File.separator + "draft.json");
2. Initialize the TAVCoverSelector launcher in the Activity's onCreate method.
coverLauncher = TAVCoverSelector.registerForResult(this, result -> {
if (result != null) {
//Handle the TAVCoverResult returned by the cover selector here.
}
});
3. Launch the cover selection screen.
// Launch the cover selector from a draft
// TAVCoverSelector.TAVCoverRequest request = TAVCoverSelector.TAVCoverRequest.fromDraft(draft);
// Launch from the current editing instance.
TAVCoverSelector.TAVCoverRequest request = TAVCoverSelector.TAVCoverRequest.fromKey(editorKey);
request.coverPlaceHolder = thumbPath;
request.renderSizeLevel = TAVEditorConstants.VIDEO_LEVEL_720P;
request.maxDuration = 20_000_000;
request.position = 10_000_000;
coverLauncher.launch(request);

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백