官网上的demo无法运行https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V4/camera-recording-case-0000001774120390-V4#ZH-CN_TOPIC_0000001857875305_完整示例
1.需要声明两个权限[‘ohos.permission.CAMERA’,‘ohos.permission.MICROPHONE’]2.使用XComponent组件配合官网示例即可运行@Component struct XComponentPage { // 创建XComponentController mXComponentController: XComponentController = new XComponentController; surfaceId: string = ''; build() { Flex({ wrap: FlexWrap.Wrap }) { // 创建XComponent XComponent({ id: '', type: 'surface', libraryname: '', controller: this.mXComponentController }) .onLoad(() => { console.log(`loading start`); // 设置Surface宽高(1920*1080),预览尺寸设置参考前面 previewProfilesArray 获取的当前设备所支持的预览分辨率大小去设置 // 预览流与录像输出流的分辨率的宽高比要保持一致1344x2772 this.mXComponentController.setXComponentSurfaceSize({ surfaceWidth: 640, surfaceHeight: 480 }); // 获取Surface ID this.surfaceId = this.mXComponentController.getXComponentSurfaceId(); console.log(`loading end surfaceId = ${JSON.stringify(this.surfaceId)}`); }) .width(640) .height(480) SaveButton() .onClick(async () => { let permissions: Permissions[] = ['ohos.permission.CAMERA','ohos.permission.MICROPHONE'] let atManager = abilityAccessCtrl.createAtManager(); await atManager.requestPermissionsFromUser(getContext(), permissions); videoRecording(getContext(), this.surfaceId)//官网示例函数 }) } } }
1.需要声明两个权限[‘ohos.permission.CAMERA’,‘ohos.permission.MICROPHONE’]
2.使用XComponent组件配合官网示例即可运行