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

小程序模板網

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

發布時間:2018-05-02 15:20 所屬欄目:小程序開發教程

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

  • 舊版錄音功能

首先啟動錄音,然后停止錄音即可拉到音頻的臨時地址

啟動錄音:


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

停止錄音:


wx.stopRecord()

播放錄音:


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

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

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


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

開始錄音:


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

結束錄音:


this.recorderManager.stop()

播放音頻:


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


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/24167.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×