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