1.1完整代码
<template><view></view>
</template><script>export default {data() {return {BGInnerAudioContext1: null, //背景1BGInnerAudioContext2: null, //背景2}},onLoad() {this.play1()this.play2()},methods: {//音频1play1() {//背景音乐this.BGInnerAudioContext1 = uni.createInnerAudioContext();this.BGInnerAudioContext1.src = '../../static/mp3/gameBg.mp3';this.BGInnerAudioContext1.play()},//音频2play2() {this.BGInnerAudioContext2 = uni.createInnerAudioContext();this.BGInnerAudioContext2.sessionCategory = "ambient" //不中止其他声音播放this.BGInnerAudioContext2.src = '../../static/mp3/transport.mp3';this.BGInnerAudioContext2.play()},}}
</script><style></style>
1.2 解决sessionCategory = "ambient"不生效
不能使用autoplay自动播放事件,必须手动.play()