HarmonyOS Camera kit 自定义相机,每次开启录像都会session.stop,再session.start。这个过程预览流会中断

await this.capSession.stop(); 
this.capSession.beginConfig(); 
if (this.photoOutput) { 
  this.capSession.removeOutput(this.photoOutput); // 移除拍照流 
  this.photoOutput = undefined 
} 
if (this.videoOutput) { 
  this.capSession.removeOutput(this.videoOutput) // 移除录像流 
} 
await this.createRecordOutput() // 创建拍照流 
this.capSession.addOutput(this.videoOutput); 
await this.capSession.commitConfig(); 
await this.capSession.start(); 
await this.videoOutput?.start(); 
await this.avRecorder?.start();

如上面代码,每次的开启录像,都会先session.stop,重新配置videoOutput,最后再session.start。这个过程预览流也会被短暂的终止,导致出现短暂的黑屏,影响用户体验。有没有办法,删除和添加videoOutput的过程不会终止预览流的输出。

HarmonyOS
2024-08-12 15:36:17
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

可以参考一下系统相机的实现方式:源码链接:https://gitee.com/openharmony/applications_camera

参考:common\src\main\ets\default\camera\CameraService.ts createSession StartRecording stopRecording

分享
微博
QQ
微信
回复
2024-08-12 19:30:26
相关问题
【求助】自定义相机Camera2焦距异常
7707浏览 • 1回复 待解决
HarmonyOS 自定义相机拍照后数据展示
223浏览 • 1回复 待解决
自定义界面扫码预览画面出现拉伸
1627浏览 • 1回复 待解决
自定义弹窗自定义转场动画
664浏览 • 1回复 待解决
HarmonyOS 如何自定义BuildMode?
112浏览 • 1回复 待解决
camera 获取预览数据
1456浏览 • 1回复 待解决