网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網(wǎng)

微信小程序錄音與播放錄音

發(fā)布時(shí)間:2018-05-02 15:20 所屬欄目:小程序開(kāi)發(fā)教程

小程序中提供了兩種錄音的API

  • 舊版錄音功能

首先啟動(dòng)錄音,然后停止錄音即可拉到音頻的臨時(shí)地址

啟動(dòng)錄音:


var that = this;
    wx.startRecord({
      success: function (res) {
       // 調(diào)用了停止錄音接口就會(huì)觸發(fā)這個(gè)函數(shù),res.tempFilePath為錄音文件臨時(shí)路徑
        var tempFilePath = res.tempFilePath
        that.setData({
          src: tempFilePath
        })
      },
      fail: function (res) {
        //錄音失敗的處理函數(shù)
      }
    })

停止錄音:


wx.stopRecord()

播放錄音:


wx.playVoice({
  filePath: src // src可以是錄音文件臨時(shí)路徑
})
  • 新版錄音

獲取全局唯一的錄音管理器,然后錄音都依賴他,而播放錄音則需要內(nèi)部 audio 上下文 innerAudioContext 對(duì)象。

獲取全局唯一的錄音管理器:


var that = this;
    this.recorderManager = wx.getRecorderManager();
    this.recorderManager.onError(function(){
      // 錄音失敗的回調(diào)處理
    });
    this.recorderManager.onStop(function(res){
      // 停止錄音之后,把錄取到的音頻放在res.tempFilePath
      that.setData({
        src: res.tempFilePath 
      })
      console.log(res.tempFilePath )
    });

開(kāi)始錄音:


this.recorderManager.start({
      format: 'mp3'  // 如果錄制acc類型音頻則改成aac
});

結(jié)束錄音:


this.recorderManager.stop()

播放音頻:


this.innerAudioContext = wx.createInnerAudioContext();
    this.innerAudioContext.onError((res) => {
     // 播放音頻失敗的回調(diào)
    })
    this.innerAudioContext.src = this.data.src;  // 這里可以是錄音的臨時(shí)路徑
    this.innerAudioContext.play()


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開(kāi)源 碼云倉(cāng)庫(kù):starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/24167.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢:800182392 點(diǎn)擊咨詢
QQ在線咨詢
AI智能客服 ×