diff --git a/feature_capabilities/src/main/ets/providers/AudioProvider.ets b/feature_capabilities/src/main/ets/providers/AudioProvider.ets index 15aa041..3544a42 100644 --- a/feature_capabilities/src/main/ets/providers/AudioProvider.ets +++ b/feature_capabilities/src/main/ets/providers/AudioProvider.ets @@ -374,20 +374,22 @@ export class AudioProvider implements CapabilityProvider { const r: RecordResult | undefined = p as RecordResult | undefined; const action: string = r !== undefined ? r.action : 'cancel'; const timeSec: number = r !== undefined ? r.timeSec : 0; + // 对齐 Android reset():任何结束(发送/取消/太短)松手瞬间都先立刻回投一次空 getaudiourl, + // H5 录音状态机据此复位;正常发送再在上传完成后补发真实 URL(复刻 Android upload()+reset() 双回投)。 + // 缺这次空回投会导致 H5 收到真实 URL 也不处理 → 录完不播放。 + this.emitAudioUrl('', 0); if (action === 'send') { const key: string = this.recorder.key(); this.recorder.stop().then((filePath: string) => this.doUpload(filePath, key, timeSec)); } else { this.recorder.cancel(); - this.emitAudioUrl('', 0); } } private async doUpload(filePath: string, key: string, timeSec: number): Promise { const ctx: common.UIAbilityContext | undefined = this.context; if (ctx === undefined || filePath === '') { - this.emitAudioUrl('', 0); - return; + return; // 已发过空回投(reset 语义);上传不了则保持"无语音" } try { const token: string = await QiniuToken.uploadToken(); @@ -400,12 +402,10 @@ export class AudioProvider implements CapabilityProvider { if (ok) { this.emitAudioUrl(`http://gameaudio.daoqi88.cn/${key}`, timeSec); } else { - this.log.w(`qiniu upload failed key=${key}`); - this.emitAudioUrl('', 0); + this.log.w(`qiniu upload failed key=${key}`); // 已发空回投,不再重复 } } catch (e) { - this.log.w(`upload error: ${(e as BusinessError).message}`); - this.emitAudioUrl('', 0); + this.log.w(`upload error: ${(e as BusinessError).message}`); // 已发空回投,不再重复 } }