uniapp 实现多音频同时播放 解决sessionCategory = “ambient“不生效问题

1.1完整代码

java 复制代码
<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()

相关推荐
音视频牛哥7 小时前
不止于超低延迟:SmartMediaKit iOS Unity3D RTSP/RTMP 播放器的核心竞争力
音视频·unity3d rtsp播放器·unity3d rtmp播放器·smartmediakit·ios unity rtsp·ios unity rtmp·unity3d ios播放器
辰辰观影9 小时前
网盘视频播放器怎么选?2026全平台推荐
经验分享·音视频
guhy fighting10 小时前
怎么去除视频的logo?现在有方法了,使用Remove Logo Now快速去除视频logo
音视频
呆呆的猫10 小时前
【视频生成】2、VDN-MiniMax-H3
音视频
沐禾安信12 小时前
MOV转MP4怎么转换?苹果视频打不开这样解决
音视频·格式转换·mov转mp4
小豆庄12 小时前
视频隐私脱敏怎么处理:识别追踪与本地方案的选型思路
密码学·音视频·视频
七牛云行业应用12 小时前
爆火OpenFilm 0.2.6:开源 AI 视频 Agent 的安装、编辑与渲染流程(2026 年 10 月 )
人工智能·开源·音视频
码匠许师傅13 小时前
【C++三方组件】FFmpeg:音视频处理的瑞士军刀
c++·ffmpeg·音视频
voipmaker1 天前
GB28181 对接踩坑实录:注册不上、目录不全、流卡顿,一次说清(附 2022 版变更清单)
物联网·音视频·实时音视频·信息与通信·iot·gb28181·国标gb28181