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();
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.

如上面代码,每次的开启录像,都会先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
相关问题
HarmonyOS 自定义相机预览问题
979浏览 • 1回复 待解决
HarmonyOS 自定义相机预览拉伸问题
878浏览 • 1回复 待解决
HarmonyOS Camera Kit相机问题
896浏览 • 1回复 待解决
【求助】自定义相机Camera2焦距异常
8986浏览 • 1回复 待解决
HarmonyOS flutter依赖插件audio_session报错
711浏览 • 1回复 待解决
HarmonyOS 自定义相机demo
1611浏览 • 1回复 待解决
HarmonyOS 如何自定义相机
874浏览 • 1回复 待解决
HarmonyOS 自定义相机功能
1009浏览 • 1回复 待解决