


Introduction to the life cycle of WeChat applet page and audio playback and monitoring
Jun 27, 2018 am 10:53 AMThis article mainly introduces the life cycle of the WeChat applet page and the relevant information on the detailed explanation of audio playback and monitoring examples. Friends in need can refer to the following
1. The life cycle of the interface
/** * 監(jiān)聽頁面加載, * 頁面加載中 */ onLoad:function(){ var _this = this console.log('index---------onload()') /** * 監(jiān)聽音樂播放 */ wx.onBackgroundAudioPlay(function() { console.log('onBackgroundAudioPlay') }), /** * 監(jiān)聽音樂暫停 */ wx.onBackgroundAudioPause(function() { console.log('onBackgroundAudioPause') }), /** * 監(jiān)聽音樂停止 */ wx.onBackgroundAudioStop(function() { console.log('onBackgroundAudioStop') util.playAudio() }) }, /** * 監(jiān)聽頁面顯示, * 當從當前頁面調轉到另一個頁面 * 另一個頁面銷毀時會再次執(zhí)行 */ onShow: function() { console.log('index---------onShow()') }, /** * 監(jiān)聽頁面渲染完成 * 完成之后不會在執(zhí)行 */ onReady: function() { console.log('index---------onReaday()'); }, /** * 監(jiān)聽頁面隱藏 * 當前頁面調到另一個頁面時會執(zhí)行 */ onHide: function() { console.log('index---------onHide()') }, /** * 當頁面銷毀時調用 */ onUnload: function() { console.log('index---------onUnload') }
2. eg: Use the system method of playing music
wx.playBackgroundAudio()
When you need to call the related operations of monitoring music, you need to do it in onLoad (in the title one)
function playAudio(){ wx.playBackgroundAudio({ dataUrl: 'http://m2.music.126.net/oO27f-6XZ2_jMV1gA8wzlA==/1319413953349380.mp3', title:'Blue Night', coverImgUrl:'http://pic.58pic.com/58pic/15/15/32/43x58PICgE2_1024.jpg', success: function(res){ // success console.log("ok") }, fail: function(res) { // fail console.log("fail") }, complete: function(res) { // complete console.log("ok") } }) }
3. Extra number : The global function is declared using
util.playAudio()The method is in the file util.js, and this file contains the global function!
The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Introduction to the Page() function of the WeChat mini program
The jump page in the WeChat mini program Two methods
The above is the detailed content of Introduction to the life cycle of WeChat applet page and audio playback and monitoring. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)