https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext
音频文件是: https://fanyi.baidu.com/gettts?lan=en&text=pregnant&spd=3&source=web
代码:
const innerAudioContext = wx.createInnerAudioContext({useWebAudioImplement: true})
innerAudioContext.autoplay = false
innerAudioContext.src = 'https://fanyi.baidu.com/gettts?lan=en&text=pregnant&spd=3&source=web';
innerAudioContext.play();
执行代码报错:
WAServiceMainContext.js:2 reporter error:Cannot read property 'indexOf' of undefined TypeError: Cannot read property 'indexOf' of undefined
at Object.errorReport (WAServiceMainContext.js:2:127516)
at r.thirdErrorReport (WAServiceMainContext.js:2:126923)
at Object.thirdErrorReport (WAServiceMainContext.js:2:130123)
at i (http://127.0.0.1:18008/appservice/__dev__/WASubContext.js?t=wechat&s=1652282634340&v=2.19.4:2:102665)
at Object.a [as cb] (http://127.0.0.1:18008/appservice/__dev__/WASubContext.js?t=wechat&s=1652282634340&v=2.19.4:2:96450)
at http://127.0.0.1:18008/appservice/__dev__/WASubContext.js?t=wechat&s=1652282634340&v=2.19.4:2:73668
at Array.forEach (<anonymous>)
at n.emit (http://127.0.0.1:18008/appservice/__dev__/WASubContext.js?t=wechat&s=1652282634340&v=2.19.4:2:73632)
at t (http://127.0.0.1:18008/appservice/__dev__/WASubContext.js?t=wechat&s=1652282634340&v=2.19.4:2:80667)
at http://127.0.0.1:18008/appservice/__dev__/WASubContext.js?t=wechat&s=1652282634340&v=2.19.4:2:81055(env: macOS,mp,1.05.2204250; lib: 2.19.4)
这个音频访问就会得到一个 mp3 格式的文件, 为何还不能播放? 是否必须直接使用文件原始地址?
createInnerAudioContext,有兼容性问题,可以参考下https://developers.weixin.qq.com/community/develop/article/doc/00004265ab0740ad9bddacb5a51813,希望能对你有帮助哦
你把{useWebAudioImplement: true}这个去掉,就可以正常播放了