破晓君
破晓君
  • 发布:2022-07-20 15:58
  • 更新:2022-07-20 15:58
  • 阅读:379

njs 安卓调用摄像头拍摄 并自定义存储位置

分类:uni-app

let status;
// 判断权限可以搜索下论坛
status = await permission.requestAndroid('android.permission.CAMERA');
status = await permission.requestAndroid('android.permission.READ_EXTERNAL_STORAGE');
const main = plus.android.runtimeMainActivity();
const mediaStore = plus.android.importClass('android.provider.MediaStore');
const Intent = plus.android.importClass('android.content.Intent');
const intent = new Intent('android.media.action.VIDEO_CAPTURE');
const File = plus.android.importClass('java.io.File');
const filePath = plus.io.convertLocalFileSystemURL('_doc/xxxxxx.mp4');
const file = new File(filePath);
const FileProvider = plus.android.importClass('io.dcloud.common.util.DCloud_FileProvider');
const outputFile = FileProvider.getUriForFile(main, ${main.getPackageName()}.dc.fileprovider, file);
intent.putExtra(mediaStore.EXTRA_VIDEO_QUALITY, 1);
intent.putExtra(mediaStore.EXTRA_OUTPUT, outputFile);
main.startActivityForResult(intent, 200);
main.onActivityResult = function(requestCode, resultCode) {
if (resultCode === 0) return;
uni.showLoading({ title: '视频压缩中', mask: true});
uni.compressVideo({
src: filePath,
quality: 'low',
complete: (res) => {
uni.hideLoading();
console.log(res.tempFilePath);
},
});
};
}

1 关注 分享
z***@126.com

要回复文章请先登录注册