微信小程序录音功能和播放音频功能实现

403 阅读1分钟

欢迎加入微信小程序开发交流qq群(173683895)相互交流学习。谢谢

源码简介: 点击按钮实现相应效果 ↓↓↓↓↓↓↓↓

//test.wxml

<button bindtap='start'>开始录音</button>  
<button bindtap='play'>播放录音</button>  
<button bindtap='stop'>停止录音</button>

//test.js

var voice = "";
Page({
  play: function () {
    //播放声音文件  
    wx.playVoice({
      filePath: voice
    })
  },
  start: function () {
    //开始录音  
    wx.startRecord({
      success: function (e) {
        voice = e.tempFilePath
      }
    })
  },
  stop: function () {
    //结束录音  
    wx.stopRecord();
  }
})