HarmonyOS录音音频如何存放,以及遍历

录音音频如何存放,放在哪个位置?以及如何遍历所有已录制音频进行展示和播放呢?

HarmonyOS
2024-09-10 11:43:17
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

可以通过AVRecorder进行音频录制 ,AVPlayer进行音频播放;通过media.AVRecorderConfig设置音视频录制的参数,其中的url可以指定录制文件的存放地址;关于AVRecorder进行音频录制的开发使用指导可参考官方文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/using-avrecorder-for-recording-V5

AVRecorderConfig参数中的url设置可参考如下链接中“新建并打开文件”那一行。https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/app-file-access-V5#新建并读写一个文件

可参考如下代码:

this.curFile = fileIo.openSync(this.filesDir + '/Audio_' + new Date().getTime() + '.mp4', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);    
this.avConfig.url = 'fd://' + this.curFile.fd;
  • 1.
  • 2.

至于如何遍历所有已录制音频进行展示和播放,可以将录制成功的文件名保存到state修饰的变量里,通过循环遍历该变量,拿到已录制的文件并进行展示,通过单击事件控制音频文件的播放;关于AVPlayer开发音频播放功能的开发使用指导可参考官方文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/using-avplayer-for-playback-V5

可参考如下代码:

Scroll() { 
  List({ space: 5 }) { 
    ForEach(this.fileNames, (item: [string, number], index: number) => { 
      ListItem() { 
        Text(`${item[0]}  ${item[1]}s`) { 
          Span(`${item[0]}  `) 
          Span(`${item[1]}s`).fontColor(Color.Blue) 
        } 
        .backgroundColor('#f1f3f5') 
        .padding({ left: 20, right: 20, top: 8, bottom: 8 }) 
        .width('100%') 
        .borderRadius(15) 
        .borderWidth(1) 
        .borderColor(this.currentIndex == index ? Color.Blue : Color.Gray) 
      } 
      .onClick(() => { 
        this.isPlay = true; 
        this.currentIndex = index; 
        let file = fileIo.openSync(`${this.filesDir}/${item[0]}`) 
        this.curFileUri = `fd://${file.fd}`; 
        this.startPlayingProcess(); 
      }) 
    }) 
  } 
} 
.scrollBar(BarState.Off)
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
分享
微博
QQ
微信
回复
2024-09-10 17:32:33
相关问题
AudioCapturer录音+AudioRenderer播放音频
2444浏览 • 1回复 待解决
HarmonyOS 如何遍历interface
603浏览 • 1回复 待解决
HarmonyOS 录音,希望能有录音Demo
960浏览 • 1回复 待解决
HarmonyOS 如何遍历对象属性
735浏览 • 1回复 待解决
HarmonyOS 如何遍历resources/rawfile目录
614浏览 • 1回复 待解决
HarmonyOS ArkTS如何循环遍历对象
1330浏览 • 1回复 待解决
HarmonyOS 录音功能问题
888浏览 • 1回复 待解决
HarmonyOS录音报错问题
1071浏览 • 1回复 待解决
HarmonyOS 用户证书的存放路径是哪里
1135浏览 • 1回复 待解决
HarmonyOS 如何实现实时录音转文字
935浏览 • 1回复 待解决
HarmonyOS 中的 .ts 代码如何遍历对象?
667浏览 • 1回复 待解决
求大佬告知如何实现录音监听
2866浏览 • 1回复 待解决
HarmonyOS 如何遍历一个JSON Object
925浏览 • 1回复 待解决
App签名依赖的文件推荐如何存放
950浏览 • 1回复 待解决
求大佬告知如何遍历JSON对象
1139浏览 • 1回复 待解决
HarmonyOS 录音上传文件
904浏览 • 1回复 待解决
HarmonyOS 录音音量获取
569浏览 • 1回复 待解决