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

相关推荐
Deitymoon37 分钟前
RV1126——YUV原理
音视频
2501_9160088942 分钟前
全面解析常用Web前端开发工具:编辑器、调试工具、性能分析器与框架
android·前端·ios·小程序·uni-app·编辑器·iphone
weixin_495248401 小时前
AI视频翻译总对不上?字幕配音时间轴是关键
人工智能·音视频
lqqjuly1 小时前
视频理解与生成解析(Video Understanding & Generation)
深度学习·音视频
Deitymoon1 小时前
RV1126——音视频开发环境搭建、固件烧录、网络调试、demo运行
音视频
西安同步高经理1 小时前
国产音频频谱分析仪使用案例,多通道音频分析仪,音频频谱分析仪
大数据·人工智能·音视频
chenying9981791 小时前
掩码扩散语音克隆:参考音频为什么会被噪声“污染“?
人工智能·音视频·语音合成
古道青阳2 小时前
构建工业级短视频生成流水线:Playwright + FFmpeg 自动化指南
运维·自动化·音视频
编程猪猪侠2 小时前
基于uni-app-x 与 uni-app 的安卓与 H5 双向通信完整实现
android·javascript·uni-app
夏夏夏果2 小时前
部署视频生成模型-美团LongCat-Video
ai·音视频