# InnerAudioContext

InnerAudioContext Example, you can use the wx.createInnerAudioContext Interface gets an instance. Note that the audio playback process may be interrupted by the system, you can use the wx.onAudioInterruptionBeginwx.onAudioInterruptionEndEvents to handle the situation.

# attribute

# string src

The address of an audio resource for direct playback. 2.2.3 Start supporting cloud file ID

# number startTime

Starting position (s), default to 0

# boolean autoplay

Whether to start playing automatically, by default false

# boolean loop

Whether to loop, by default false

# boolean obeyMuteSwitch

Follow the system mute switch, default to trueWhen the parameter is false Even if the user opens the mute switch, the sound can continue to be emitted. from 2.3.0 This parameter does not take effect when version begins, using the wx.setInnerAudioOption Interface unified settings.

# number volume

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

Volume. range 01。 Default is 1

# number playbackRate

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

Playback speed. range 0.5-2.0 by default 1。(Android Need 6 And above)

# number duration

Length of current audio in units s)。 Only in the current legal src Returns (Read Only) when

# number currentTime

Current audio playback position in units s)。 Only in the current legal src Time is reserved after the decimal point 6 Bit (read only)

# boolean paused

Is the current pause or stop state (Read Only)

# number buffered

Audio buffered time point, only to ensure that the current playback time point content is buffered at this time point (Read Only)

# string referrerPolicy

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

origin: Send the full referrer no-referrer: Do not send. Format fixed to https://servicewechat.com/{appid} /{version}/page-frame.htmlWhere {appid} For Mini Program appid,{version} Is the version number of the Mini Program, which is 0 Represents a development version, a trial version, and a review version with a version number of devtools Represented as developer tools and the rest as official versions

# method

# InnerAudioContext.play()

play

# InnerAudioContext.pause()

Time out. Playback of paused audio starts at the paused point

# InnerAudioContext.stop()

Stop. After the stop audio replay will be played from the beginning.

# InnerAudioContext.seek(number position)

Jump to the specified location

# InnerAudioContext.destroy()

Destroy current instance

# InnerAudioContext.onCanplay(function callback)

Listen for events in which audio enters playable state. But it doesn't guarantee a smooth playback

# InnerAudioContext.offCanplay(function callback)

Event that cancels listening for audio entering playable state

# InnerAudioContext.onPlay(function callback)

Listen for audio playback events

# InnerAudioContext.offPlay(function callback)

Unlisten Audio Playback Event

# InnerAudioContext.onPause(function callback)

Listening for audio pause events

# InnerAudioContext.offPause(function callback)

Unlisten Audio Pause Event

# InnerAudioContext.onStop(function callback)

Listen for audio stop events

# InnerAudioContext.offStop(function callback)

Cancel listening audio stop event

# InnerAudioContext.onEnded(function callback)

Listen to events where audio plays naturally to the end

# InnerAudioContext.offEnded(function callback)

Unlisten for audio natural playback to the end of the event

# InnerAudioContext.onTimeUpdate(function callback)

Listen to audio playback progress update events

# InnerAudioContext.offTimeUpdate(function callback)

Unlisten audio playback progress update event

# InnerAudioContext.onError(function callback)

Listen for audio playback error events

# InnerAudioContext.offError(function callback)

Unlisten Audio Playback Error Event

# InnerAudioContext.onWaiting(function callback)

Listen for audio loading events. Triggered when audio needs to be stopped and loaded due to insufficient data

# InnerAudioContext.offWaiting(function callback)

Unlistening for Audio Loading Events

# InnerAudioContext.onSeeking(function callback)

Listen to audio jump operation event

# InnerAudioContext.offSeeking(function callback)

Cancel listening audio jump operation event

# InnerAudioContext.onSeeked(function callback)

Listen for audio events to complete jump operations

# InnerAudioContext.offSeeked(function callback)

Unlisten for an event that completes a jump operation with audio

# Support format

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.with/M500001VfvsJ21xFqb.mp3guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'
innerAudioContext.onPlay(() => {
  console.log("Start playing.")
})
innerAudioContext.onError((res) => {
  console.log(res.errMsg)
  console.log(res.errCode)
})