当前位置:网站首页>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
边栏推荐
- GoLand 2021.1.1: configure the multi line display of the tab of the open file
- Implementation of Muduo accept connection, disconnection and sending data
- 【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
- SQL Injection (POST/Search)
- Open PHP error prompt under Ubuntu 14.04
- Disruptor -- a high concurrency and high performance queue framework for processing tens of millions of levels
- 3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
- Qt学习17 对话框及其类型
- Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)
- Using registered classes to realize specific type matching function template
猜你喜欢

Internet of things completion -- (stm32f407 connects to cloud platform detection data)

Go language web development series 29: Gin framework uses gin contrib / sessions library to manage sessions (based on cookies)

Complete deep neural network CNN training with tensorflow to complete picture recognition case 2

Common network state detection and analysis tools
![[technology development-24]: characteristics of existing IOT communication technology](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[technology development-24]: characteristics of existing IOT communication technology

How to use lxml to judge whether the website announcement is updated

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

Logback log sorting

8 Queen question

挡不住了,国产芯片再度突进,部分环节已进到4nm
随机推荐
SQL Injection (GET/Search)
项目协作的进度如何推进| 社区征文
JS convert pseudo array to array
RichView TRVStyle ListStyle 列表样式(项目符号编号)
Asp. Net core1.1 without project JSON, so as to generate cross platform packages
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
Go: send the get request and parse the return JSON (go1.16.4)
金属有机骨架MOFs装载非甾体类抗炎药物|ZIF-8包裹普鲁士蓝负载槲皮素(制备方法)
Qt学习17 对话框及其类型
Go language web development series 27: Gin framework: using gin swagger to implement interface documents
【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
SQL Injection (GET/Select)
Use vscode to view hex or UTF-8 codes
Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
Mastering the cypress command line options is the basis for truly mastering cypress
如何使用lxml判断网站公告是否更新
Windos creates Cordova prompt because running scripts is prohibited on this system
GoLand 2021.1.1: configure the multi line display of the tab of the open file
Field problems in MySQL