# InnerAudioContext

The InnerAudioContext instance can be obtained through the API wx.createInnerAudioContext.

# Properties

# string src

The audio file address which can be used to play the audio file directly. Base library 2.2.3 or above supports cloud file IDs.

# number startTime

The position where the playback starts (in sec). It is 0 by default.

# boolean autoplay

Whether to enable auto playback. It is false by default.

# boolean loop

Whether to enable loop playback. It is false by default.

# boolean obeyMuteSwitch

Whether to follow the "Mute" switch. It is true by default. If it is set to false, the audio file still sounds even if the "Mute" switch is on. As of base library 2.3.0, this parameter does not take effect and the feature is set through the API wx.setInnerAudioOption.

# number volume

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

Specifies the volume, which ranges from 0 to 1. It is 1 by default.

# number duration

The length of the audio file (in sec). It is only returned when a valid src attribute exists (read only).

# number currentTime

The position where the playback has got to (in sec). It is only returned when a valid src attribute exists and is rounded to six decimal places (read only).

# boolean paused

Whether the playback is paused or stopped (read only).

# number buffered

The position where the audio is buffered. Only the part between the position where the playback has got to and this position is buffered (read only).

# Methods

# InnerAudioContext.play()

Plays an audio file.

# InnerAudioContext.pause()

Pauses the audio playback. The playback is resumed at the point where it was paused.

# InnerAudioContext.stop()

Stops the audio playback. The playback starts from the beginning if the file is played again.

# InnerAudioContext.seek(number position)

Jumps to the specific position.

# InnerAudioContext.destroy()

Terminates the current instance.

# InnerAudioContext.onCanplay(function callback)

Listens on the event that an audio file is ready for playback. A smooth playback is not guaranteed.

# InnerAudioContext.offCanplay(function callback)

Un-listens on the event that an audio file is ready for playback.

# InnerAudioContext.onPlay(function callback)

Listens on the audio playback event.

# InnerAudioContext.offPlay(function callback)

Un-listens on the audio playback event.

# InnerAudioContext.onPause(function callback)

Listens on the audio pause event.

# InnerAudioContext.offPause(function callback)

Un-listens on the audio pause event.

# InnerAudioContext.onStop(function callback)

Listens on the event of stopping audio playback.

# InnerAudioContext.offStop(function callback)

Un-listens on the event of stopping audio playback.

# InnerAudioContext.onEnded(function callback)

Listens on the event of playing an audio file to the end without interruption.

# InnerAudioContext.offEnded(function callback)

Un-listens on the event of playing an audio file to the end without interruption.

# InnerAudioContext.onTimeUpdate(function callback)

Listens on the event of updating audio playback progress.

# InnerAudioContext.offTimeUpdate(function callback)

Un-listens on the event of updating audio playback progress.

# InnerAudioContext.onError(function callback)

Listens on the audio playback error event.

# InnerAudioContext.offError(function callback)

Un-listens on the audio playback error event.

# InnerAudioContext.onWaiting(function callback)

Listens on the audio loading event. It is triggered when the playback of an audio file stops to load the file due to insufficient data.

# InnerAudioContext.offWaiting(function callback)

Un-listens on the audio loading event.

# InnerAudioContext.onSeeking(function callback)

Listens on the event of jumping to a specific position in the audio file.

# InnerAudioContext.offSeeking(function callback)

Un-listens on the event of jumping to a specific position in the audio file.

# InnerAudioContext.onSeeked(function callback)

Listens on the event of finishing the jump to a specific position in the audio file.

# InnerAudioContext.offSeeked(function callback)

Un-listens on the event of finishing the jump to a specific position in the audio file.

# Supported Formats

Format iOS Android
flac x
m4a
ogg x
ape x
amr x
wma x
wav
mp3
mp4 x
aac
aiff x
caf x

# Sample Code

const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.autoplay = true
innerAudioContext.src = 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'
innerAudioContext.onPlay(() => {
  console.log('Start playback')
})
innerAudioContext.onError((res) => {
  console.log(res.errMsg)
  console.log(res.errCode)
})