May 18, 2021 WeChat Mini Program Development Document
InnerAudioContext instance, which can be obtained through the wx.createInnerAudioContext interface.
The address of the audio resource for direct playback. 2.2.3 Start supporting cloud file IDs
Where playback starts (in:s), which defaults to 0
Whether to start playback automatically, the default is false
Whether to loop, the default is false
Whether to follow the system mute switch, the default is true. W hen this parameter is false, the sound continues even if the user turnes on the mute switch. This parameter does not take effect from version 2.3.0 and is set uniformly using the wx.setInnerAudioOption interface.
Volume. R ange 0 to 1. The default is 1
Play speed. R ange 0.5-2.0, default to 1. (Android requires 6 and above versions)
The length of the current audio in s. Return only if there is a legitimate src (read-only)
The current audio playback position in s. Returned only if there is a legitimate src at the present time, 6 bits after the time is reserved for the number of points (read only)
Whether to pause or stop state (read-only)
Audio buffering point in time, only to ensure that the content is buffered (read-only) from the current playback point in time to this point in time
Destroy the current instance
Base library 1.9.0 starts to support, and low versions need to be compatible.
Cancels the event that listens for audio into a play-playing state
The callback function for an event in which audio enters a playable state
Base library 1.9.0 starts to support, and low versions need to be compatible.
Cancel the event that listens to audio that naturally plays to the end
The callback function of the audio that naturally plays to the end event
Base library 1.9.0 starts to support, and low versions need to be compatible.
Cancel listening for audio playback error events
The callback function for the audio playback error event
Base library 1.9.0 starts to support, and low versions need to be compatible.
Cancel the listening audio pause event
The callback function for the audio pause event
Base library 1.9.0 starts to support, and low versions need to be compatible.
Cancel listening for audio playback events
The callback function for the audio playback event
Base library 1.9.0 starts to support, and low versions need to be compatible.
Cancel the event that the audio is listening to complete the jump operation
The callback function for the event in which the audio completes the jump operation
Base library 1.9.0 starts to support, and low versions need to be compatible.
The event that cancels the jump operation by listening to audio
A callback function for events in which audio jumps
Base library 1.9.0 starts to support, and low versions need to be compatible.
Cancel listening for audio stop events
The callback function for the audio stop event
Base library 1.9.0 starts to support, and low versions need to be compatible.
Cancel listening to audio playback progress update events
The callback function for the audio playback progress update event
Base library 1.9.0 starts to support, and low versions need to be compatible.
Cancel listening for events in the audio load
The callback function for events in the audio load
Listen for events where audio enters a play-playing state. However, there is no guarantee that the back will play smoothly
The callback function for an event in which audio enters a playable state
Listen for events in which audio plays naturally to the end
The callback function of the audio that naturally plays to the end event
Listen for audio playback error events
The callback function for the audio playback error event
Property | Type | Description |
---|---|---|
errMsg | string | |
errCode | number |
The legal value of errCode
Value | Description | The lowest version |
---|---|---|
10001 | System error | |
10002 | Network error | |
10003 | The file is wrong | |
10004 | The format is wrong | |
-1 | Unknown error |
Listen for audio pause events
The callback function for the audio pause event
Listen for audio playback events
The callback function for the audio playback event
Listen for events in which audio completes a jump operation
The callback function for the event in which the audio completes the jump operation
Listen for events in which audio jumps
A callback function for events in which audio jumps
Listen for audio stop events
The callback function for the audio stop event
Listen for audio playback progress update events
The callback function for the audio playback progress update event
Listen for events in the audio load. It fires when audio needs to stop loading because there is not enough data
The callback function for events in the audio load
Time out. Paused audio playback starts at the pause
Play
Jump to the specified location
The time of the jump, in s. 3 bits after the exact number of points, which supports ms-level accuracy
Stop it. Audio playback after stopping plays from scratch.
Format | Ios | Android |
---|---|---|
Flac | Ⅹ | √ |
m4a | √ | √ |
ogg | Ⅹ | √ |
ape | Ⅹ | √ |
Amr | Ⅹ | √ |
Wma | Ⅹ | √ |
Wav | √ | √ |
mp3 | √ | √ |
mp4 | Ⅹ | √ |
Aac | √ | √ |
aiff | √ | Ⅹ |
Caf | √ | Ⅹ |
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('开始播放')
})
innerAudioContext.onError((res) => {
console.log(res.errMsg)
console.log(res.errCode)
})