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

相关推荐
hz567893 小时前
电子远程评标系统哪家好?安全、合规、易用平台评测指南
安全·云计算·音视频·实时音视频·信息与通信
星空语5 小时前
音频001_Android+Linux车载/手机音频全链路分层架构图
android·linux·音视频
hz567897 小时前
局域网视频会议解决方案,适配政企专网场景
音视频·实时音视频·信息与通信·安全架构
敖行客 Allthinker8 小时前
UniApp iOS APNs 推送证书一站式配置
uni-app·mac
Cutecat_9 小时前
YouTube 多语种自动配音功能实测:AI 如何让一条视频“开口说”多种语言
人工智能·科技·音视频
潜创微科技9 小时前
国产 USB3.0 千兆网卡芯片 CH9153:Pin-to-Pin 替换 RTL8153,免改板、免驱、工业级
音视频
梦曦i10 小时前
uni-router新推useUniEventChannel,彻底解决页面通信难题
前端·uni-app
宠友信息10 小时前
内容社区源码多端数据协议与 Spring Boot 状态流转实现思路
java·spring boot·websocket·uni-app
2501_9159184112 小时前
PerfDog 太贵?iOS 性能监控工具的功能对比与选择
android·ios·小程序·https·uni-app·iphone·webview
PedroQue9912 小时前
uni-router新推useUniEventChannel,彻底解决页面通信难题
前端·uni-app