uniapp jumps to the page to stop audio playback

Requirement: Terminate the audio being played when jumping to the page

Implementation;

1: uniapp official API

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



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

2: Vue life cycle

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

Guess you like

Origin blog.csdn.net/m0_72196169/article/details/130843683