Taro.playVoice(option)
Starts the playback of a voice file. Only one file can be played at a time. The start of the playback of a file will stops the in-progress playback of the previous one.
Type
(option: Option) => Promise<CallbackResult>
Parameters
Option
Property | Type | Required | Description |
---|---|---|---|
filePath | string | Yes | The path of the voice file to be played |
duration | number | No | Specifies the recording duration (in sec). The recording stops automatically when the specified number of seconds elapse. |
complete | (res: any) => void | No | The callback function used when the API call completed (always executed whether the call succeeds or fails) |
fail | (res: any) => void | No | The callback function for a failed API call |
success | (res: Result) => void | No | The callback function for a successful API call |
Sample Code
Taro.startRecord({
success: function (res) {
const tempFilePath = res.tempFilePath
Taro.playVoice({
filePath: tempFilePath,
complete: function () { }
})
}
})
API Support
API | WeChat Mini-Program | H5 | React Native |
---|---|---|---|
Taro.playVoice | ✔️ |