This API is called using wx.stopVoice(Object object).
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
wx.startRecord({success (res) {const tempFilePath = res.tempFilePathwx.playVoice({filePath: tempFilePath,})setTimeout(() => { wx.stopVoice() }, 5000)}})
This API is called using wx.playVoice(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | The file path of the voice file to be played (local path). |
duration | number | 60 | False | Specifies the duration of playback in seconds. Playback will stop automatically after this duration. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
wx.startRecord({success (res) {const tempFilePath = res.tempFilePathwx.playVoice({filePath: tempFilePath,complete () { }})}})
This API is called using wx.pauseVoice(Object object).
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
wx.startRecord({success (res) {const tempFilePath = res.tempFilePathwx.playVoice({filePath: tempFilePath})setTimeout(() => { wx.pauseVoice() }, 5000)}})
This API is called using wx.setInnerAudioOption(Object object).
Property | Type | Default value | Required | Description |
mixWithOther | boolean | true | False | Whether to mix with other audio. If set to true, it won't stop other app's music. |
obeyMuteSwitch | boolean | true | False | (iOS only) Whether to follow the mute switch. If set to false, it can play sound even in silent mode. |
speakerOn | boolean | true | False | true means using the speaker, false means using the handset. Default is true. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
This API is called using wx.getAvailableAudioSources(Object object).
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
audioSources | Array.<string> |
Value | Description |
auto | Automatically set. Uses phone mic by default, switches to headset mic when plugged in. Applicable to all platforms. |
buildInMic | Phone microphone, iOS only. |
headsetMic | Headset microphone, iOS only. |
mic | Microphone (phone mic when no headset, headset mic when plugged in), Android only. |
camcorder | Same as mic, suitable for recording audio/video content, Android only. |
voice_communication | Same as mic, suitable for real-time communication, Android only. |
voice_recognition | Same as mic, suitable for voice recognition, Android only. |
This API is called using AudioContext wx.createAudioContext(string id, Object this).
This method is called using AudioContext.pause().
This method is called using AudioContext.play ().
This method is called using AudioContext.seek(number position).
This method is called using AudioContext.setSrc(string src).
This API is called using InnerAudioContext wx.createInnerAudioContext(Object object).
audio
context, i.e., an InnerAudioContext object.const innerAudioContext = wx.createInnerAudioContext()innerAudioContext.src = 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'innerAudioContext.play() // Play the audioinnerAudioContext.pause () // Pause the audioinnerAudioContext.stop () // Stop the audioinnerAudioContext.destroy () // Release audio resources
Format | iOS | Android |
flac | x | √ |
m4a | √ | √ |
ogg | x | √ |
ape | x | √ |
amr | x | √ |
wma | x | √ |
wav | √ | √ |
mp3 | √ | √ |
mp4 | x | √ |
aac | √ | √ |
aiff | √ | x |
caf | √ | x |
const innerAudioContext = wx.createInnerAudioContext()innerAudioContext.autoplay = trueinnerAudioContext.src = 'https://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'innerAudioContext.onPlay(() => {console.log('Starts to play')})innerAudioContext.onError((res) => {console.log(res.errMsg)console.log(res.errCode)})
This method is called using InnerAudioContext.play ().
This method is called using InnerAudioContext.pause().
This method is called using InnerAudioContext.stop().
This method is called using InnerAudioContext.seek(number position).
This method is called using InnerAudioContext.destroy ().
This method is called using InnerAudioContext.onCanplay(function listener).
This method is called using InnerAudioContext.offCanplay(function listener).
const listener = function (res) { console.log(res) }InnerAudioContext.onCanplay(listener)InnerAudioContext.offCanplay(listener) // Must pass the same function object used in onCanplay
This method is called using InnerAudioContext.onPlay(function listener).
This method is called using InnerAudioContext.offPlay(function listener).
const listener = function (res) { console.log(res) }InnerAudioContext.onPlay(listener)InnerAudioContext.offPlay(listener) // Must pass the same function object used in onPlay
This method is called using InnerAudioContext.onPause(function listener).
This method is called using InnerAudioContext.offPause(function listener).
const listener = function (res) { console.log(res) }InnerAudioContext.onPause(listener)InnerAudioContext.offPause(listener) // Must pass the same function object used in onPause
This method is called using InnerAudioContext.onStop(function listener).
const listener = function (res) { console.log(res) }InnerAudioContext.onStop(listener)InnerAudioContext.offStop(listener) // Must pass the same function object used in onStop
This method is called using InnerAudioContext.onEnded(function listener).
This method is called using InnerAudioContext.offEnded(function listener).
const listener = function (res) { console.log(res) }InnerAudioContext.onEnded(listener)InnerAudioContext.offEnded(listener) // Must pass the same function object used in onEnded
This method is called using InnerAudioContext.onTimeUpdate(function listener).
This method is called using InnerAudioContext.offTimeUpdate(function listener).
const listener = function (res) { console.log(res) }InnerAudioContext.onTimeUpdate(listener)InnerAudioContext.offTimeUpdate(listener) // Must pass the same function object used in onTimeUpdate
This method is called using InnerAudioContext.onError(function listener).
Property | Type | Description |
errMsg | string | |
errCode | number | |
Value | Description |
10001 | System error. |
10002 | Network error. |
10003 | File error. |
10004 | Format error. |
-1 | Unknown error. |
This method is called using InnerAudioContext.offError(function listener).
const listener = function (res) { console.log(res) }InnerAudioContext.onError(listener)InnerAudioContext.offError(listener) // Must pass the same function object used in onError
This method is called using InnerAudioContext.onWaiting(function listener).
This method is called using InnerAudioContext.offWaiting(function listener).
const listener = function (res) { console.log(res) }InnerAudioContext.onWaiting(listener)InnerAudioContext.offWaiting(listener) // Must pass the same function object used in onWaiting
This method is called using InnerAudioContext.onSeeking(function listener).
This method is called using InnerAudioContext.offSeeking(function listener).
const listener = function (res) { console.log(res) }InnerAudioContext.onSeeking(listener)InnerAudioContext.offSeeking(listener) // Must pass the same function object used in onSeeking
This method is called using InnerAudioContext.onSeeked(function listener).
This method is called using InnerAudioContext.offSeeked(function listener).
const listener = function (res) { console.log(res) }InnerAudioContext.onSeeked(listener)InnerAudioContext.offSeeked(listener) // Must pass the same function object used in onSeeked