当前位置:网站首页>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
边栏推荐
- JSON serialization case summary
- Go 1.16.4: purpose of go mod tidy
- Go language unit test 3: go language uses gocovey library to do unit test
- HALCON联合C#检测表面缺陷——HALCON例程autobahn
- Error handling when adding files to SVN:.... \conf\svnserve conf:12: Option expected
- Replace the GPU card number when pytorch loads the historical model, map_ Location settings
- Go language web development series 27: Gin framework: using gin swagger to implement interface documents
- AI scores 81 in high scores. Netizens: AI model can't avoid "internal examination"!
- MySQL 数据增删改查综合案例
- mysql中的字段问题
猜你喜欢

Golang — 命令行工具cobra

Comprehensively develop the main channel of digital economy and digital group, and actively promote the utonmos digital Tibet market

Can newly graduated European college students get an offer from a major Internet company in the United States?

PhpMyAdmin stage file contains analysis traceability

掌握Cypress命令行选项,是真正掌握Cypress的基础

【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
![[sort] bucket sort](/img/52/95514b5a70cea75821883e016d8adf.jpg)
[sort] bucket sort

Screenshot of the operation steps of upload labs level 4-level 9

Conversion function and explicit
![Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:](/img/2f/33504391a661ecb63d42d75acf3a37.png)
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
随机推荐
Unity Render Streaming通过Js与Unity自定义通讯
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 web development series 29: Gin framework uses gin contrib / sessions library to manage sessions (based on cookies)
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes
Thrift threadmanager and three monitors
Field problems in MySQL
Kivy tutorial how to automatically load kV files
Can newly graduated European college students get an offer from a major Internet company in the United States?
Qt学习17 对话框及其类型
Qt学习25 布局管理器(四)
【被动收入如何挣个一百万】
Complete deep neural network CNN training with tensorflow to complete picture recognition case 2
核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)
TensorBoard可视化处理案例简析
Qt学习20 Qt 中的标准对话框(中)
8 Queen question
Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:
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
Spark practice 1: build spark operation environment in single node local mode
使用Tensorflow进行完整的深度神经网络CNN训练完成图片识别案例2