- 需求的场景描述(希望解决的问题)
音频mp3播放,开发工具没问题,真机模拟无法获取duration,无法播放,监听事件没有错
const innerAudioContext = wx.createInnerAudioContext(); page( onload:(){ wx.request({ url: radioUrl, method: 'POST' , data: { id: that.data.poetryId }, header: { 'Content-Type' : 'application/json' }, success: (res) => { if (res.data.status == 0) { console.log( "******play******" ) that.setData({ audiolist: [ { audiosrc: hostUrl + 'static/' + res.data.data.audio, coverimg: "" } ], }) innerAudioContext.autoplay = true //音频初始化 that.Initialization(); } } }) } //音频初始化 函数 //初始化播放器,获取duration Initialization() { var t = this ; if ( this .data.audiolist[0].audiosrc.length != 0) { //设置src innerAudioContext.src = this .data.audiolist[0].audiosrc; //运行一次 innerAudioContext.play() innerAudioContext.pause() innerAudioContext.onCanplay(() => { //初始化duration innerAudioContext.duration setTimeout( function () { //延时获取音频真正的duration var duration = innerAudioContext.duration; var min = parseInt(duration / 60); var sec = parseInt(duration % 60); if (min.toString().length == 1) { min = `0${min}`; } if (sec.toString().length == 1) { sec = `0${sec}`; } t.setData({ audioDuration: innerAudioContext.duration, showTime2: `${min}:${sec}` }); console.log( "&&&&声音长度END" + innerAudioContext.duration) }, 1000) }) innerAudioContext.onEnded((res) => { console.log( '播放结束!' ); }) // 播放音频失败的回调 innerAudioContext.onError((res) => { console.log( '播放音频失败' + res); }) innerAudioContext.onStop((res) => { console.log( '停止播放!' ); }) } }, ) |
- 希望提供的能力
音频mp3播放,可以获取时长
这请问解决了吗
我也遇到了 ,不仅不能播放,而且还重复调用API,几天前还正常的。。。
麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
https://developers.weixin.qq.com/s/mtzb3dmi7I9A
较多报错,麻烦重新提供下
那个不重要,主要逻辑都有了