has.stopVoice(Object object)
结束播放语音。
起始版本: 1.0.16
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码信息:
| 错误码 | 错误信息 |
|---|---|
| 101 | AVPlayer is not initialized. |
| 102 | 1. AVPlayer can not be stop. 2. src is invalid or inaccessible |
| 70003503 | 1. stopVoice error. 2. stopAudio error. 更多错误信息参考:Media错误码。 |
示例:
has.stopVoice({
success: () => {
console.info('stopVoice success');
},
fail: (err) => {
console.error('stopVoice fail', err);
},
complete: (res) => {
console.info('stopVoice complete', res);
}
}); has.playVoice(Object object)
开始播放语音。同时只允许一个语音文件正在播放,如果前一个语音文件还没播放完,将中断前一个语音播放。
起始版本: 1.0.16
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 默认值 | 必填 | 描述 |
|---|---|---|---|---|
| filePath | string | - | 是 | 需要播放的语音文件的文件路径。 |
| duration | number | 60 | 否 | 指定播放时长,到达指定的播放时长后会自动停止播放,单位:s。 |
| success | function | - | 否 | 接口调用成功的回调函数。 |
| fail | function | - | 否 | 接口调用失败的回调函数。 |
| complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
| 错误码 | 错误信息 |
|---|---|
| 101 | AVPlayer is not initialized. |
| 102 | 1. src is invalid or inaccessible;AVPlayer can not be stop. 2. filePath is invalid or inaccessible. |
| 70003401 | AVPlayer can not reset. |
| 70003501 | playVoice error. 更多错误信息参考:Media错误码。 |
示例:
has.playVoice({
filePath: 'internal://tmp/template.mp3',
success: () => {
console.info('playVoice success');
},
fail: (err) => {
console.error('playVoice fail', err);
},
complete: (res) => {
console.info('playVoice complete', res);
}
}); has.pauseVoice(Object object)
暂停正在播放的语音。再次调用 has.playVoice 播放同一个文件时,会从暂停处开始播放。如果想从头开始播放,需要先调用 has.stopVoice。
起始版本: 1.0.16
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码信息:
| 错误码 | 错误信息 |
|---|---|
| 70003502 | 1. pauseVoice error. 2. pauseAudio error. 更多错误信息参考:Media错误码。 |
示例:
has.pauseVoice({
success: () => {
console.info('pauseVoice success');
},
fail: (err) => {
console.error('pauseVoice fail', err);
},
complete: (res) => {
console.info('pauseVoice complete', res);
}
});