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

How to play audio in uni-app

藏色散人
Release: 2023-01-13 00:44:43
Original
14393 people have browsed it

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;
	});}
Copy after login
and calls

//这里接口需要请求,判断是否需要播放语音提示
this.ScanAudio();//播放语音
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template