当前位置:网站首页>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
边栏推荐
- C language standard IO function sorting
- 使用tensorflow进行完整的DNN深度神经网络CNN训练完成图片识别案例
- Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
- CVPR 2022 | interpretation of 6 excellent papers selected by meituan technical team
- Father and basketball
- Go 1.16.4: purpose of go mod tidy
- 全面发展数字经济主航道 和数集团积极推动UTONMOS数藏市场
- Mastering the cypress command line options is the basis for truly mastering cypress
- GoLand 2021.1: rename the go project
- Leetcode-1175. Prime Arrangements
猜你喜欢

3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)

Go language unit test 3: go language uses gocovey library to do unit test

GoLand 2021.1.1: configure the multi line display of the tab of the open file

CVPR 2022 | 美团技术团队精选6篇优秀论文解读

使用Tensorflow进行完整的深度神经网络CNN训练完成图片识别案例2
![[technology development-24]: characteristics of existing IOT communication technology](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[technology development-24]: characteristics of existing IOT communication technology

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.

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

Common network state detection and analysis tools
随机推荐
MySQL data processing value addition, deletion and modification
Go: send the get request and parse the return JSON (go1.16.4)
SQL Injection (GET/Select)
[556. Next larger element III]
Kivy tutorial how to load kV file design interface by string (tutorial includes source code)
Comprehensive case of MySQL data addition, deletion, modification and query
Qt学习19 Qt 中的标准对话框(上)
Error handling when adding files to SVN:.... \conf\svnserve conf:12: Option expected
研发团队资源成本优化实践
Comprehensive evaluation of double chain notes remnote: fast input, PDF reading, interval repetition / memory
解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
从零开始的基于百度大脑EasyData的多人协同数据标注
Multi person collaborative data annotation based on Baidu brain easydata from scratch
Flutter动态化 | Fair 2.5.0 新版本特性
怎样删除对象的某个属性或⽅法
Unity embeddedbrowser browser plug-in event communication
Leetcode-1175.Prime Arrangements
JS convert pseudo array to array
[技术发展-24]:现有物联网通信技术特点
[how to earn a million passive income]