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()

相关推荐
EasyGBS20 分钟前
ONVIF设备接入国标GB28181视频平台EasyGBS:不用国标也能一键拉流!
服务器·php·音视频
2501_916007473 小时前
iOS和macOS应用程序性能分析和优化工具使用综合指南
android·macos·ios·小程序·uni-app·iphone·webview
音视频牛哥3 小时前
SmartMediaKit 推拉流MP4录像实践:实时传输与本地留存一体化
音视频·rtmp推流录像·rtmp播放端录像·rtsp播放端录像·rtsp流录制·rtmp流录制·rtsp服务器录像
石臻臻的杂货铺4 小时前
做 AI 视频,先让 Blender 把镜头演一遍
人工智能·音视频·blender
ALINX技术博客4 小时前
【黑金云课堂】FPGA技术教程Vitis开发:SD卡WAV文件读取音频播放实验
fpga开发·音视频
沐禾安信21 小时前
AVI 视频打不开?2026 四款转 MP4 工具封神
音视频·电脑录屏
兵叔物联1 天前
基于FFmpeg的短视频自动剪辑工具
ffmpeg·音视频
AORUO奥偌1 天前
从“拼凑”到“集成”:音视频系统如何重塑弱电智能化建设逻辑
音视频·公共广播系统·音视频系统·多媒体会议与ip广播系统·多媒体会议系统
禹亮科技1 天前
大型国企会议室音视频集成实战:3间120㎡空间Poly G7500+LED大屏+讯飞多语言会议系统落地方案
音视频·视频会议系统集成·上海禹亮科技·讯飞听见多语言会议系统·poly g7500
音视频牛哥1 天前
SmartMediaKit macOS版RTSP/RTMP低延迟播放器:技术架构、核心能力与应用实践
音视频·低延迟rtsp播放器·macos直播播放器·macos rtsp播放器·macos rtmp播放器·rtsp播放器mac版·rtmp播放器mac版