Home  >  Article  >  Web Front-end  >  How to play audio in uni-app

How to play audio in uni-app

藏色散人
藏色散人Original
2021-09-17 15:21:3614324browse

Methods for uni-app to play audio: 1. Introduce "Vue.prototype.ScanAudio = function() {...}" in main.js; 2. Pass "this.ScanAudio();" The method can be called on the page.

How to play audio in uni-app

The operating environment of this article: windows7 system, uni-app version 2.5.1, DELL G3 computer.

How does uni-app play audio?

uniapp Play audio

##Project requirements, when the status A voice prompt needs to be broadcast when updating.

main.js introduces

Vue.prototype.ScanAudio = function() {
	var music = null;
	music = uni.createInnerAudioContext(); //创建播放器对象
	music.src = "../../static/mp3/fy-cn.mp3";
	music.play(); //执行播放
	music.onEnded(() => {
		//播放结束
		music = null;
	});}
and calls

//这里接口需要请求,判断是否需要播放语音提示
this.ScanAudio();//播放语音
Recommended: "

uni-app tutorial

The above is the detailed content of How to play audio in uni-app. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn