返回

专注连锁门店会员营销管理系统

线上+线下+进销存+收银+会员
HiShop > Hi小程序 > 小程序开发 > 开发实例 >

小程序wx.getRecorderManager()录音管理

2020-09-27 作者:秩名

小程序中提供了两种录音的API,wx.startRecord和wx.getRecorderManager(),接下来为大家介绍后者。
小程序wx.getRecorderManager()录音管理

1.小程序录音管理介绍 wx.getRecorderManager()

基础库 1.6.0 开始支持,低版本需做兼容处理,获取全局唯一的录音管理器 recorderManager。

2.小程序录音管理代码

// 录音管理
let record = function (recorderManager) {
  this.recorderManager = recorderManager
  this.recordStart()
}
record.prototype = {
  // 开始录音
  start: function (startObj) {
    this.recorderManager.start(startObj)
  },
  //录音开始事件
  recordStart: function () {
    this.recorderManager.onStart(() => {
      console.log(this.recorderManager, 'this.recorderManager')
    })
  }
}

3.Page onLoad配置

  //录音管理,new 出 第二阶段的实例
    recorderManager = wx.getRecorderManager()
    that.newRecord = new record(recorderManager)
     that.newRecord.recorderManager.onStop((res) => {
         console.log(res, '获取录制完的链接')
    })
    //播放录音
    innerAudioContext = wx.createInnerAudioContext()
    innerAudioContext.onEnded(() => {
      console.log("音频自然播放结束")
    })

4.现在开始录音

    startRecord() {
        let that = this,
          startObj = {
            duration: 60000,
            sampleRate: 44100,
            numberOfChannels: 1,
            encodeBitRate: 192000,
            format: 'mp3',
            frameSize: 50
          }
        //录音开始
        that.newRecord.start(startObj)
        // 录音计时器
        recordTimeInterval = setInterval(function () {
        }, 1000)
  },

5.停止录音

  stopRecord() {
    clearInterval(recordTimeInterval);
    //停止录音事件
    this.newRecord.recorderManager.stop()
  }

6.播放录音

          // 播放录音
          playVoice(e) {
            let that = this
            let srcPath = e.currentTarget.dataset.temppath, // 点击当前传递的播放链接
                  duration = e.currentTarget.dataset.duration, // 录音时间
                  index = e.currentTarget.dataset.index // 索引
            checkArr[index] = srcPath   //用于页面判断播放一个,另一个暂停
            // 播放
            innerAudioContext.obeyMuteSwitch = false
            innerAudioContext.src = srcPath
            innerAudioContext.play()
            // 时间减少器
            playTimeInterval = setInterval(() => {
              let playTime = that.data.playTime += 1
            }, 1000)
          }

7.停止播放

        // 停止播放
          stopVoice(forIndex, e) {
            let index;
            e !== undefined ? index = e.currentTarget.dataset.index : index = forIndex
            clearInterval(playTimeInterval)
            checkArr[index] = undefined
            innerAudioContext.stop()
          }

8.只能播放一个的代码

          // 只能播放一个
          onePlayFor(tempFilePath, src) {
            tempFilePath.forEach((el, i) => {
              if (el.tempFilePath !== src) {
                this.stopVoice(i)
              }
            })
          }
录音与停止录音使用小程序bind:touchstart='startRecord' bind:touchend='stopRecord' 事件

小程序wx.getRecorderManager()录音管理

线上+线下+进销存+收银+会员门店零售管理好帮手

  • 极速收银管理

    门店能实现快速收银,提升门店经营效率。

  • 进销存管理

    系统自带进销存管理,更好管理库存销售。

  • 软硬件一体化

    配备收银硬件一站式整体服务。

收 银 会员管理 库存管理 商品管理 交接班 数据报表 营销促单 售后处理 多种收款

获取报价
【本站声明】

1、本网站发布的该篇文章,目的在于分享电商知识及传递、交流相关电商信息,以便您学习或了解电商知识,请您不要用于其他用途;
2、该篇文章中所涉及的商标、标识的商品/服务并非来源于本网站,更非本网站提供,与本网站无关,系他人的商品或服务,本网站对于该类商标、标识不拥有任何权利;
3、本网站不对该篇文章中所涉及的商标、标识的商品/服务作任何明示或暗示的保证或担保;
4、本网站不对文章中所涉及的内容真实性、准确性、可靠性负责,仅系客观性描述,如您需要了解该类商品/服务详细的资讯,请您直接与该类商品/服务的提供者联系。

推荐文章

门店系统 获取报价 立即咨询 免费试用