其實這個API也挺奇葩的,錄音結束後success不走,complete不走,fail也不走, 不知道是不是因爲電腦測試的原因,只能等公測或者等他們完善。以後再測和補充吧!!!!
主要屬性:
wx.startRecord(object)
手動調用wx.stopRecord()停止錄音
wxml
<!--用於記錄時間-->
<text>{{formatRecordTime}}</text>
<button type="primary" bindtap="listenerButtonStartRecord">開始錄音</button>
<button type="primary" bindtap="listenerButtonStopRecord">結束錄音</button>
js
var util = require('../../../utils/util.js')
var interval
Page({
data:{
//錄音顯示類型
formatRecordTime: '00:00:00',
//計數
recordTime: 0,
},
onLoad:function(options){
// 頁面初始化 options爲頁面跳轉所帶來的參數
},
/**
* 監聽按鈕點擊開始錄音
*/
listenerButtonStartRecord: function() {
that = this;
interval = setInterval(function() {
that.data.recordTime += 1
that.setData({
//格式化時間顯示
formatRecordTime: util.formatTime(that.data.recordTime)
})
}, 1000)
wx.startRecord({
success: function(res) {
console.log(res)
that.setData({
//完成之後重新繪製
formatRecordTime: util.formatTime(that.data.recordTime)
})
},
/**
* 完成清除定時器
*/
complete: function() {
clearInterval(interval)
}
})
},
/**
* 監聽手動結束錄音
*/
listenerButtonStopRecord: function() {
wx.stopRecord();
clearInterval(interval);
this.setData({
formatRecordTime: '00:00:00',
recordTime: 0
})
},
onReady:function(){
// 頁面渲染完成
},
onShow:function(){
// 頁面顯示
},
onHide:function(){
// 頁面隱藏
},
/**
* 當界面關閉時停止定時器關閉錄音
*/
onUnload:function(){
// 頁面關閉
wx.stopRecord()
clearInterval(interval)
}
})