Detailed description of the mini-program Audio API and instance code, audioapi
Nothing worth too much attention
Important attributes:
1. wx. getBackgroundAudioPlayerState (object) Get the playback status
2. wx. playBackgroundAudio (object) Play Music
3. wx. pauseBackgroundAudio () pause music
4. wx. seekBackgroundAudio (object) sets the playback progress
5. wx. stopBackgroundAudio () stops playing music.
Three listeners:
Wxml
<Button type = "primary" bindtap = "listenerButtonPlay"> play </button> <button type = "primary" bindtap = "listenerButtonPause"> pause </button> <button type = "primary" bindtap = "listenerButtonSeek"> set the playback progress </button> <button type = "primary" bindtap = "listenerButtonStop"> stop playback </button> <button type =" primary "bindtap =" listenerButtonGetPlayState "> get the playback status </button>
Js
Page ({data: {// text: "This is a Page"}, listenerButtonPlay: function () {wx. playBackgroundAudio ({// playback address dataUrl: 'http: // audio, // title music name title: 'qingyunzhi', // picture address coverImgUrl: 'http: // r1.ykimg.com/050E0000576B75F667BC3C136B06E4E7'})},/*** playback status */listenerButtonGetPlayState: function () {wx. getBackgroundAudioPlayerState ({success: function (res) {console. log (res) // total duration // currentPosition current playback position // status playback status // downloadPercent Download status: 100 // dataUrl current playback music address }})}, /*** pause button for listening button */listenerButtonPause: function () {wx. pauseBackgroundAudio () ;},/***** set progress */listenerButtonSeek: function () {wx. seekBackgroundAudio ({position: 30})},/*** stop playing */listenerButtonStop: function () {wx. stopBackgroundAudio ()}, onLoad: function (options) {// parameters of page initialization options for page Jump/*** listen to music play */wx. onBackgroundAudioPlay (function () {console. log ('onbackgroundaudioplay')})/*** listen to music pause */wx. onBackgroundAudioPause (function () {console. log ('onbackgroundaudiopause')})/*** listen to music stop */wx. onBackgroundAudioStop (function () {console. log ('onbackgroundaudiostop')}, onReady: function () {// page rendering completed}, onShow: function () {// page display}, onHide: function () {// page hiding}, onUnload: function () {// page closing }})
Thank you for reading this article and hope to help you. Thank you for your support for this site!