当前位置:网站首页>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
边栏推荐
- TensorBoard可视化处理案例简析
- Flutter dynamic | fair 2.5.0 new version features
- Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)
- IBEM 数学公式检测数据集
- Mycms we media mall v3.4.1 release, user manual update
- Open PHP error prompt under Ubuntu 14.04
- Qt学习25 布局管理器(四)
- Complete deep neural network CNN training with tensorflow to complete picture recognition case 2
- Swiftui development experience: the five most powerful principles that a programmer needs to master
- PhpMyAdmin stage file contains analysis traceability
猜你喜欢
解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
Using registered classes to realize specific type matching function template
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Unity embeddedbrowser browser plug-in event communication
The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
Use vscode to view hex or UTF-8 codes
GoLand 2021.1.1: configure the multi line display of the tab of the open file
[技術發展-24]:現有物聯網通信技術特點
全面发展数字经济主航道 和数集团积极推动UTONMOS数藏市场
【电脑插入U盘或者内存卡显示无法格式化FAT32如何解决】
随机推荐
Qt学习23 布局管理器(二)
Unity EmbeddedBrowser浏览器插件事件通讯
JVM系列——概述,程序计数器day1-1
The shadow of the object at the edge of the untiy world flickers, and the shadow of the object near the far point is normal
Go language unit test 4: go language uses gomonkey to test functions or methods
Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
顺序表(C语言实现)
Qt学习21 Qt 中的标准对话框(下)
Brief analysis of tensorboard visual processing cases
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
SQL Injection (POST/Select)
How to use lxml to judge whether the website announcement is updated
Go: send the get request and parse the return JSON (go1.16.4)
Which securities company has the lowest Commission for opening an account online? I want to open an account. Is it safe for the online account manager to open an account
Qt学习24 布局管理器(三)
SQL Injection (AJAX/JSON/jQuery)
如何使用lxml判断网站公告是否更新
Go language web development series 29: Gin framework uses gin contrib / sessions library to manage sessions (based on cookies)
【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
There is nothing new under the sun. Can the meta universe go higher?