当前位置:网站首页>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
边栏推荐
- 太阳底下无新事,元宇宙能否更上层楼?
- JVM family - overview, program counter day1-1
- Box layout of Kivy tutorial BoxLayout arranges sub items in vertical or horizontal boxes (tutorial includes source code)
- GoLand 2021.1.1: configure the multi line display of the tab of the open file
- PHP maze game
- Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
- KEIL5出现中文字体乱码的解决方法
- 【556. 下一个更大元素 III】
- Sequence table (implemented in C language)
- Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu
猜你喜欢
AI scores 81 in high scores. Netizens: AI model can't avoid "internal examination"!
Bidirectional linked list (we only need to pay attention to insert and delete functions)
Comprehensive case of MySQL data addition, deletion, modification and query
Several common optimization methods matlab principle and depth analysis
Can newly graduated European college students get an offer from a major Internet company in the United States?
Mastering the cypress command line options is the basis for truly mastering cypress
Libuv Library - Design Overview (Chinese version)
解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
使用tensorflow进行完整的DNN深度神经网络CNN训练完成图片识别案例
随机推荐
Can newly graduated European college students get an offer from a major Internet company in the United States?
Field problems in MySQL
Go 1.16.4: purpose of go mod tidy
Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
Swiftui development experience: the five most powerful principles that a programmer needs to master
Bidirectional linked list (we only need to pay attention to insert and delete functions)
Logback log sorting
树的深入和广度优先遍历(不考虑二叉树)
Golang - command line tool Cobra
Open PHP error prompt under Ubuntu 14.04
Error running 'application' in idea running: the solution of command line is too long
【电脑插入U盘或者内存卡显示无法格式化FAT32如何解决】
怎样删除对象的某个属性或⽅法
Spark practice 1: build spark operation environment in single node local mode
Stack application (balancer)
软件测试工作那么难找,只有外包offer,我该去么?
Use and design of Muduo buffer class
Qt学习23 布局管理器(二)
Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)