wx.getBackgroundAudioPlayerState(OBJECT)

获取音乐播放状态。

OBJECT参数说明:

参数 类型 必填 说明
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

success返回参数说明:

参数 说明
duration 选定音频的长度(单位:s),只有在当前有音乐播放时返回
currentPosition 选定音频的播放位置(单位:s),只有在当前有音乐播放时返回
status 播放状态(2:没有音乐在播放,1:播放中,0:暂停中)
downloadPercent 音频的下载进度(整数,80 代表 80%),只有在当前有音乐播放时返回
dataUrl 歌曲数据链接,只有在当前有音乐播放时返回

示例代码:

wx.getBackgroundAudioPlayerState({
    success: function(res) {
        var status = res.status
        var dataUrl = res.dataUrl
        var currentPosition = res.currentPosition
        var duration = res.duration
        var downloadPercent = res.downloadPercent
    }
})

wx.playBackgroundAudio(OBJECT)

播放音乐,同时只能有一首音乐正在播放。

OBJECT参数说明

参数 类型 必填 说明
dataUrl String 音乐链接
title String 音乐标题
coverImgUrl String 封面URL
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

wx.playBackgroundAudio({
    dataUrl: '',
    title: '',
    coverImgUrl: ''
})

wx.pauseBackgroundAudio()

暂停播放音乐。

示例代码

wx.pauseBackgroundAudio()

wx.seekBackgroundAudio(OBJECT)

控制音乐播放进度。

OBJECT参数说明

参数 类型 必填 说明
position Number 音乐位置,单位:秒
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

wx.seekBackgroundAudio({
    position: 30
})

wx.stopBackgroundAudio()

停止播放音乐。

示例代码

wx.stopBackgroundAudio()

wx.onBackgroundAudioPlay(CALLBACK)

监听音乐播放。

wx.onBackgroundAudioPause(CALLBACK)

监听音乐暂停。

wx.onBackgroundAudioStop(CALLBACK)

监听音乐停止。

个结果 ""

    没有找到相关内容 ""