小程序学习之媒体API(二)录音管理

使用wx.getRecorderManager()获取全局唯一的录音管理器recorderManager,其recorderManager对象方法如下:

start(options)方法的参数说明如下:

采样率和码率关系如下:

audioSource的有效值如下:

onFrameRecorded(callback)回调结果如下:

录音管理的简单应用示例:

<!--wxml-->
<view class="title">第6章 媒体API</view>
<view class="demo-box">
 <view class="title">录音管理器</view>
 <button type="primary" size="mini" bindtap="start">开始录音</button>
 <button type="primary" size="mini" bindtap="stop">停止录音</button>
</view>

//js
Page({
  start:function(){
    const options = {
      duration:10000,
      sampleRate:44100,
      numberOfChannels:1,
      encodeBitRate:192000,
      format:'mp3',
      frameSize:50
    }
    this.rm.start(options)
  },
  stop:function(options){
   this.rm.stop()
  },
  onLoad:function(options){
    this.rm = wx.getRecorderManager()
    this.rm.onStop((res) => {
      //播放录音内容
      const audioCtx = wx.createInnerAudioContext()
      audioCtx.src = res.tempFilePath
      audioCtx.play()
    })
  }
})

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值