当前位置:网站首页>Uniapp tips - set background music
Uniapp tips - set background music
2022-07-03 13:54:00 【Cloud and cloud discoloration 1】
There's a recent uniapp There is a need to set background music , I checked some information , Want to achieve through common components , But there are too many pages . Finally, I found a way to avoid page by page modification , And in the process of using it, I found something that could not be explained in this method, and made up for it myself , Make a note of .
1、app.vue Set the background music component
onLaunch: function() {
this.bgmMusic = uni.createInnerAudioContext();
this.bgmMusic.autoplay = true;// Auto play
this.bgmMusic.loop = true;// Loop Playback
this.bgmMusic.src = '../static/audio/bg.mp3';// Background music address
this.bgmMusic.volume = 0.3;// The volume
this.bgmMusic.onPlay(function(){
console.log(' Background music playing ');
});
},
2、 Other things that need to be stopped page Stop can be set in
Here is a place to pay attention to app.vue Objects in use getApp() Method
onLoad() {
this.bgmMusic = getApp().bgmMusic;
this.bgmMusic.stop();
this.bgmMusic.onStop(()=>{
console.log(' The background music stopped ');
});
},
Reference material :
https://blog.csdn.net/weixin_45324044/article/details/108463019
https://uniapp.dcloud.io/api/media/audio-context
https://ask.dcloud.net.cn/question/79033
边栏推荐
- Windos creates Cordova prompt because running scripts is prohibited on this system
- IBEM mathematical formula detection data set
- Box layout of Kivy tutorial BoxLayout arranges sub items in vertical or horizontal boxes (tutorial includes source code)
- SQL Injection (GET/Search)
- How to use lxml to judge whether the website announcement is updated
- logback日志的整理
- Golang - command line tool Cobra
- Swiftui development experience: the five most powerful principles that a programmer needs to master
- 常见的几种最优化方法Matlab原理和深度分析
- Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
猜你喜欢

MySQL 数据增删改查综合案例

Qt学习19 Qt 中的标准对话框(上)

Students who do not understand the code can also send their own token, which is easy to learn BSC

SQL Injection (POST/Search)

Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware

Flutter dynamic | fair 2.5.0 new version features

Unity embeddedbrowser browser plug-in event communication

HALCON联合C#检测表面缺陷——HALCON例程autobahn

There is nothing new under the sun. Can the meta universe go higher?

logback日志的整理
随机推荐
[sort] bucket sort
Go 1.16.4: purpose of go mod tidy
JS convert pseudo array to array
挡不住了,国产芯片再度突进,部分环节已进到4nm
Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
SQL Injection (POST/Select)
[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心
Field problems in MySQL
Mastering the cypress command line options is the basis for truly mastering cypress
Logback log sorting
User and group command exercises
项目协作的进度如何推进| 社区征文
JSON serialization case summary
Comprehensively develop the main channel of digital economy and digital group, and actively promote the utonmos digital Tibet market
The network card fails to start after the cold migration of the server hard disk
Common network state detection and analysis tools
Qt学习17 对话框及其类型
Go language web development series 27: Gin framework: using gin swagger to implement interface documents
SQL Injection (AJAX/JSON/jQuery)
Libuv Library - Design Overview (Chinese version)