implementation 'com.yunxiao.tavmagic:tavmagicuikit:x.x.x'
<com.yunxiao.tavmagic.uikit.TAVEditorUIKitandroid:id="@+id/editor_ui"android:layout_width="match_parent"android:layout_height="match_parent" />
TAVEditorUIKit editor = findViewById(R.id.editor_ui);// Initialization Method 1: Use a list of video pathsList<String> videoPaths = Arrays.asList("path1.mp4", "path2.mp4");editor.initWithClipPath(videoPaths);// Initialization Method 2: Use a draftTAVDraft draft = loadDraft();editor.initWithDraft(draft);
@Overrideprotected void onResume() {super.onResume();editor.onResume(true); // true indicates that playback will resume.}@Overrideprotected void onPause() {super.onPause();editor.onPause();}@Overrideprotected void onDestroy() {super.onDestroy();editor.onDestroy();}@Overridepublic void onBackPressed() {if (!editor.onBackPressed()) {super.onBackPressed();}}
// Set Permission Providereditor.setPermissionProvider(new ITAVPermissionProvider() {@Overridepublic boolean checkPermission(String permission) {return ContextCompat.checkSelfPermission(MainActivity.this, permission)== PackageManager.PERMISSION_GRANTED;}@Overridepublic void requestPermission(String permission, TAVConsumer<Boolean> callback) {ActivityCompat.requestPermissions(MainActivity.this,new String[]{permission}, REQUEST_CODE);}});
public class TAVMagicAdaptActivity extends AppCompatActivity {private static final String TAG = "TAVMagicAdaptActivity";private static final float TARGET_WIDTH_DP = 375;private Context mCustomCtx;@Overrideprotected 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;}@Overridepublic Resources getResources() {return (mCustomCtx != null && mCustomCtx.getResources() != null)? mCustomCtx.getResources() : super.getResources();}}
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. |
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. |
TAVEditorUIKit for export or cover selection.String editorKey = mViewBinding.uiKit.forkOffscreenEditor();
TAVDraft object from the local draft path.TAVDraft draft = TAVDraft.createFromJsonPath(draftDir + File.separator + "draft.json");
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.}});
// 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);
피드백