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

相关推荐
Geek_Vison33 分钟前
保险APP已经用了Flutter,还能接入小程序吗?
flutter·小程序·uni-app·mpaas·小程序容器
技灵AI1 小时前
AI 带货视频会被限流吗?AIGC 标识、功效演示、同质化量产与画质四项判定对照
人工智能·aigc·音视频·ai电商·seedance
Black蜡笔小新2 小时前
老旧小区改造难题:新旧摄像头如何统一接入?EasyCVR一招融合
网络·音视频·easycvr
揽秀亭长3 小时前
视频转脚本怎么处理更高效?四种工具的工作流程与适用场景分析
人工智能·音视频·语音识别
昨日之日20063 小时前
Winxvideo:AI全能工具,智能修复老视频照片、清理噪音、录屏剪辑超方便
人工智能·音视频
_大峰_4 小时前
索尼 A7M4 误删视频恢复实战:基于原始卡镜像重建 MP4 数据
ffmpeg·数据恢复·音视频·mp4·exfat
AOI小白新手上路6 小时前
视频去雨·论文蒸馏笔记:从物理先验到状态空间模型
数据库·笔记·音视频
小码哥0686 小时前
搭建短剧系统|海外短剧:从需求到上线的指南
网络·数据库·音视频·短剧小程序·短剧系统·短剧开发·短剧后台
怪奇云呼军6 小时前
教育试听预约后没到课,闪电智能 Voice Agent 如何做分层回访?
人工智能·python·算法·云计算·音视频
做萤石二次开发的哈哈7 小时前
带摄像头的号角怎么对接?从音视频对讲链路到音频参数配置的实施要点
物联网·音视频·语音对讲·萤石开放平台·蓝海aiot一站式工作台·语音喊话·园区广播