微信小程序如何实现背景音乐开发教程详细?

更新于
2026-09-28 14:38:10
1阅读来源:SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计388个文字,预计阅读时间需要2分钟。

微信小程序如何实现背景音乐开发教程详细?

wx.getBackgroundAudioManager() 推荐大家使用背景音乐功能。若使用 audio 标签播放音乐,加载时间长,体验要求高,相关文档请查看:https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.

wx.getBackgroundAudioManager()

推荐大家使用背景音乐不在使用audio

audio播放音频加载时间长 体验需求达不到

相关文档

developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.html

相关代码

const bgMusic = wx.getBackgroundAudioManager() //创建背景音乐 Page({ data: { id: '',//请求数据参数id musicMsg: {},//接收数据对象 }, onLoad: function (options) { var that = this that.setData({ id: options.id, }) that.getPicInfo() //请求服务器 }, // 开始播放 listenerButtonPlay: function (src) { var that = this console.log(src) bgMusic.src = src; bgMusic.onTimeUpdate(() => { //监听音频播放进度 console.log(bgMusic.currentTime) }) bgMusic.onEnded(() => { //监听音乐自然播放结束 console.log("音乐播放结束"); that.listenerButtonPlay(that.data.musicMsg.mp3) }) bgMusic.play(); //播放音乐 }, getPicInfo() { var that = this wx.request({ url: 'xxxxx.xxxxx.com/1.json?id=' + that.data.id, header: { 'content-type': 'application/json' }, method: 'GET', success: function (res) { that.listenerButtonPlay(res.data.data.mp3) //成功回调执行播放音乐 that.setData({ musicMsg: res.data.data, //赋值对象 }) } }) }, onUnload() { var that = this that.listenerButtonStop()//页面卸载时停止播放 console.log("离开") }, //暂停 audioPause: function () { var that = this bgMusic.pause(); //暂停播放音乐 console.log('暂停') }, audioPlay: function () { var that = this bgMusic.play(); //停止播放 console.log('继续播放') }, //停止播放 listenerButtonStop: function () { bgMusic.stop() }, })

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。

微信小程序如何实现背景音乐开发教程详细?

本文共计388个文字,预计阅读时间需要2分钟。

微信小程序如何实现背景音乐开发教程详细?

wx.getBackgroundAudioManager() 推荐大家使用背景音乐功能。若使用 audio 标签播放音乐,加载时间长,体验要求高,相关文档请查看:https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.

wx.getBackgroundAudioManager()

推荐大家使用背景音乐不在使用audio

audio播放音频加载时间长 体验需求达不到

相关文档

developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.html

相关代码

const bgMusic = wx.getBackgroundAudioManager() //创建背景音乐 Page({ data: { id: '',//请求数据参数id musicMsg: {},//接收数据对象 }, onLoad: function (options) { var that = this that.setData({ id: options.id, }) that.getPicInfo() //请求服务器 }, // 开始播放 listenerButtonPlay: function (src) { var that = this console.log(src) bgMusic.src = src; bgMusic.onTimeUpdate(() => { //监听音频播放进度 console.log(bgMusic.currentTime) }) bgMusic.onEnded(() => { //监听音乐自然播放结束 console.log("音乐播放结束"); that.listenerButtonPlay(that.data.musicMsg.mp3) }) bgMusic.play(); //播放音乐 }, getPicInfo() { var that = this wx.request({ url: 'xxxxx.xxxxx.com/1.json?id=' + that.data.id, header: { 'content-type': 'application/json' }, method: 'GET', success: function (res) { that.listenerButtonPlay(res.data.data.mp3) //成功回调执行播放音乐 that.setData({ musicMsg: res.data.data, //赋值对象 }) } }) }, onUnload() { var that = this that.listenerButtonStop()//页面卸载时停止播放 console.log("离开") }, //暂停 audioPause: function () { var that = this bgMusic.pause(); //暂停播放音乐 console.log('暂停') }, audioPlay: function () { var that = this bgMusic.play(); //停止播放 console.log('继续播放') }, //停止播放 listenerButtonStop: function () { bgMusic.stop() }, })

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。

微信小程序如何实现背景音乐开发教程详细?