我正在使用android原生相机构建一个应用程序,我也使用新的API活动结果和合同来调用相机,使用这个方法:
ActivityResultContracts.CaptureVideo
我必须把视频的时长限制在三分钟以内。
我该怎么做呢?
通过创建ActivityResultcontracts.TakeVideo
的子类并覆盖createIntent
函数
public class customVideo extends ActivityResultContracts.TakeVideo{
@NonNull
@Override
public Intent createIntent(Context context, Uri input) {
Intent intent = super.createIntent(context, input);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 5); /* set duration limit */
return intent;
}
}
创建ActivityResultLauncher<Uri>
时使用自定义类
ActivityResultLauncher<Uri> launcher = registerForActivityResult(
new customVideo(), /* use your custom class */
new ActivityResultCallback<Bitmap>() {
@Override
public void onActivityResult(Bitmap result) {
/* code */
}
}
);
然后像以前一样捕获视频:
launcher.launch(uri);