uniapp跳转页面停止音频播放

需求:在跳转页面的时候将正在播放的音频终止

实现方法;

1:uniapp官方API

uni.addInterceptor('navigateTo', { //监听跳转的方式
				success: (e) => {
//voicePath为音频路径
					innerAudioContext.src = this.voicePath;
//stop()停止
					innerAudioContext.stop();
				}
			})



//其余跳转方式:
'redirectTo', //监听关闭本页面跳转
'switchTab',  //监听tabBar跳转
'navigateBack', //监听返回

2:vue生命周期

onUnload() {
//随便给个值来赋值,不然会报错,也可以赋值路径
            innerAudioContext.src = '1111111'
//关闭
			innerAudioContext.stop();
			
		},

猜你喜欢

转载自blog.csdn.net/m0_72196169/article/details/130843683
今日推荐