# WebAudioContext wx.createWebAudioContext()

Start from base library version 2.19.0. Please remaining backward compatible.

with Promise style call: Not supported

Mini Program plugin: Not supported

create WebAudio Context. This interface is currently in the Beta Version, in which the latest developer tools and iOS client has support debugging, Android client is in grayscale testing, the current version may be unstable, please use caution in production environment.

# Return value

# WebAudioContext

# sample code

A simple play demo


const audioCtx = wx.createWebAudioContext()

const loadAudio = (url) => {
  return new Promise((resolve) => {
    wx.request({
      url,
      responseType: 'arraybuffer',
      success: res => {
        console.log('res.data', res.data)
        audioCtx.decodeAudioData(res.data, buffer => {
          resolve(buffer)
        }, err => {
          console.error('decodeAudioData fail', err)
          reject()
        })
      },
      fail: res => {
        console.error('request fail', res)
        reject()
      }
    })
  })
}

const play = () => {
  loadAudio('xxx-test.mp3').then(buffer => {
    const source = audioCtx.createBufferSource()
    source.buffer = buffer
    source.connect(audioCtx.destination)
    source.start()
  }).catch(() => {
    console.log('fail')
  })
}

play()