const createInnerAudioContext = Taro.createInnerAudioContext();
if (createInnerAudioContext) {
Taro.setInnerAudioOption({
obeyMuteSwitch: false // 解决有一些IOS无法播放音频
})
}
handlePlay = () => {
//设置播放src
createInnerAudioContext.src = encodeURI(url); // encodeURI解决IOS无妨辨别地址存在中文的音频文件
createInnerAudioContext.autoplay = true;
createInnerAudioContext.play();
createInnerAudioContext.pause();
createInnerAudioContext.onError((res) => {
console.log(res);
});
createInnerAudioContext.onPause(() => {
//监听播放暂停事件
});
createInnerAudioContext.onPlay(() => {
//监听开始播放事件
});
}
Taro实现音乐播放
于 2023-03-08 11:37:09 首次发布