1.1完整代码
<template>
<view>
</view>
</template>
<script>
export default {
data() {
return {
BGInnerAudioContext1: null, //背景1
BGInnerAudioContext2: null, //背景2
}
},
onLoad() {
this.play1()
this.play2()
},
methods: {
//音频1
play1() {
//背景音乐
this.BGInnerAudioContext1 = uni.createInnerAudioContext();
this.BGInnerAudioContext1.src = '../../static/mp3/gameBg.mp3';
this.BGInnerAudioContext1.play()
},
//音频2
play2() {
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()
文章来源地址https://uudwc.com/A/rZ2WM
文章来源:https://uudwc.com/A/rZ2WM