innerAudioContext 2个问题(重复调用和不能播放)
发布于 6 年前 作者 jing13 6413 次浏览 来自 问答
  • 当前 Bug 的表现 

1,重复调用?

2, play不能播放?

  • 预期表现
  • 复现路径
  • 提供一个最简复现 Demo

wxml文件:

<view>

<text >长按按钮录音,松开按钮是播放:</text>

<view style=‘width:200rpx; height: 90rpx;border:1px solid #000; padding:20rpx;margin-top:20rpx;’ bindtouchstart=‘newRead’ bindtouchend=‘compareRead’>测试按钮</view>

</view>

==================================

js文件:

const recorderManager = wx.getRecorderManager()

//音频组件控制

const innerAudioContext = wx.createInnerAudioContext()

Page({

/**

  * 页面的初始数据

  */

data: {

},

/**

  * 生命周期函数–监听页面加载

  */

onLoad: function (options) {

},

newRead: function (e) {

this._record();

},

compareRead: function (e) {

this._stop();

this._play();

},

//开始录音

_record: function () {

// 手机震动

wx.vibrateShort({

})

// 录音文件

const options = {

duration: 60000, //指定录音的时长,单位 ms

sampleRate: 16000, //采样率

numberOfChannels: 1, //录音通道数

encodeBitRate: 96000, //编码码率

format: ‘mp3’, //音频格式,有效值 aac/mp3

frameSize: 50, //指定帧大小,单位 KB

}

//开始录音

recorderManager.start(options);

recorderManager.onStart(() => {

console.log(“开始录音:”)

});

//错误回调

recorderManager.onError((res) => {

console.log(res);

})

},

//停止录音

_stop: function () {

recorderManager.stop();

recorderManager.onStop((res) => {

console.log(“stop luyin!”)

this.setData({

tempFilePath: res.tempFilePath,

})

})

},

_play: function () {

innerAudioContext.autoplay = true

innerAudioContext.src = this.data.tempFilePath,

innerAudioContext.onPlay(() => {

console.log(‘开始播放’)

})

innerAudioContext.onStop(() => {

console.log(‘录音播放停止’);

})

innerAudioContext.onEnded(() => {

})

innerAudioContext.onError((res) => {

console.log(res.errMsg)

console.log(res.errCode)

})

},

})

回到顶部