uniapp H5 实现录音功能(js-audio-recorder)

原博客文档:vue使用js-audio-recorder实现录音功能_qsya的博客-CSDN博客

改为uniapp里实现 > > > 

1.添加实现的按钮

<view>
    <button @tap="start">开始录音</button>
    <button @tap="stop">停止录音</button>
    <button @tap="play">播放录音</button>
</view>

2.下载 js-audio-recorder 组件

npm i js-audio-recorder

3.引入 js-audio-recorder 插件

import Recorder from 'js-audio-recorder';

4.实例化 js-audio-recorder

created() {
    this.recorder = new Recorder()
},

5.实现代码

// 开始录音
    start() {
      this. Recorder = new Recorder()
      Recorder.getPermission().then(() => {
        console.log('开始录音')
        this.recorder.start() // 开始录音
      }, (error) => {
        this.$message({
          message: '请先允许该网页使用麦克风',
          type: 'info'
        })
        console.log(`${error.name} : ${error.message}`)
      })
    },
    stop() {
      console.log('停止录音')
      this.recorder.stop() // 停止录音
    },
    play() {
      console.log('播放录音')
      console.log(this.recorder)
      this.recorder.play() // 播放录音

      // 播放时长
      this.timer = setInterval(() => {
        try {
          this.playTime = this.recorder.getPlayTime()
        } catch (error) {
          this.timer = null
        }
      }, 100)
    }

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值