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

相关推荐
巴巴博一28 分钟前
uni-app / 微信小程序中 open-type=“share“ 按钮样式异常,和普通 view 无法齐平的解决方案
微信小程序·uni-app·notepad++
AI25122443 分钟前
AI视频生成工具怎么选,参考图与首尾帧控制能力
人工智能·机器学习·音视频
博客zhu虎康1 小时前
智能轮播Swiper:视频图片混播
音视频
oort1231 小时前
VLStream 全开源决策式 AI 视频平台 技术视角完整说明
大数据·开发语言·人工智能·经验分享·python·开源·音视频
游九尘13 小时前
JavaScript 实现三段式版本号对比函数(app升级用)
javascript·uni-app
2501_9160074713 小时前
前端开发常用软件与工具全面指南
android·ios·小程序·https·uni-app·iphone·webview
木斯佳14 小时前
鸿蒙开发入门指南:前端开发者快速理解视频编码概念——输入模式
华为·音视频·harmonyos
2501_9159090618 小时前
iOS应用性能优化:十大策略提升用户体验与开发效率
android·ios·小程序·https·uni-app·iphone·webview
EasyDSS18 小时前
私有化音视频系统/视频直播点播/高清点播/云点播/云直播EasyDSS优化升级重塑智慧文旅直播运营新体系
音视频
CV实验室20 小时前
Remote Sensing 29个SITS基准数据集综述:多模态遥感分类的新起点
人工智能·深度学习·计算机视觉·音视频