Commit 94759aba authored by Tt's avatar Tt

fix(语音功能): 修复语音按钮点击和录音关闭逻辑问题

parent d6b97261
......@@ -1353,9 +1353,7 @@
"__id__": 25
},
"_enabled": true,
"_clip": {
"__uuid__": "8bbf063f-fd82-4e2c-b54d-0997b6004b2c"
},
"_clip": null,
"_volume": 1,
"_mute": false,
"_loop": false,
......@@ -1434,9 +1432,7 @@
"__id__": 27
},
"_enabled": true,
"_clip": {
"__uuid__": "36ab29df-0eff-40ad-bd25-daa3d15f55cd"
},
"_clip": null,
"_volume": 1,
"_mute": false,
"_loop": false,
......@@ -3758,7 +3754,7 @@
"__id__": 111
}
],
"_active": false,
"_active": true,
"_components": [
{
"__id__": 113
......@@ -4485,8 +4481,10 @@
"_fontSize": 130,
"_lineHeight": 130,
"_enableWrapText": false,
"_N$file": null,
"_isSystemFontUsed": true,
"_N$file": {
"__uuid__": "23f9661e-5c67-41a5-abdf-65a4b99ef31b"
},
"_isSystemFontUsed": false,
"_spacingX": 0,
"_batchAsBitmap": false,
"_styleFlags": 0,
......
......@@ -692,6 +692,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.renderProgressLabel(label_progress);
}
onTouchVoice() {
// 使用pg.ts的API播放音频
const currentData = this.currentTouchNode.data;
pg.audio.playAudioByUrl(currentData.audioUrl);
}
/**
* 处理语音按钮的显示和事件绑定
* @param btn_voice 语音按钮节点
......@@ -702,10 +707,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 如果数据中有audio,显示语音按钮
pg.view.visible(btn_voice, true);
// 绑定点击事件播放音频
pg.view.touchOn(btn_voice, () => {
// 使用pg.ts的API播放音频
pg.audio.playAudioByUrl(currentData.audioUrl);
}, this);
pg.view.touchOn(btn_voice, this.onTouchVoice, this);
} else {
// 没有音频则隐藏按钮
pg.view.visible(btn_voice, false);
......@@ -809,11 +811,26 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.stopVoiceAni();
}
}
onTouchSpeakClose() {
private onTouchSpeakCloseClosing: boolean;
async onTouchSpeakClose() {
if (this.onTouchSpeakCloseClosing) return;
this.onTouchSpeakCloseClosing = true;
// 检查是否在录音状态
const btn_stop = pg.view.find(this.layout_speak, 'btn_stop');
if (btn_stop && btn_stop.active) {
// 如果在录音状态,先执行停止录音操作
await this.onTouchRecordEnd()
}
this.onTouchSpeakCloseClosing = false;
this.showCard(false);
// 获取最后一次录音数据
const lastVoice = Game.getIns().player.getLastVoice();
if (lastVoice.questionId != this.touchData.id) {
this.onRecordFail();
return;
}
// 如果有录音数据,则使用其分数
if (lastVoice && lastVoice.result && lastVoice.questionId == this.touchData.id) {
const score = lastVoice.result.overall;
......@@ -935,6 +952,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
* 停止倒计时,显示播放和重新录制按钮,结束录音
*/
private onTouchRecordEnd() {
return new Promise(async (resolve, reject) => {
// 使用更新后的showCard方法,传入'recorded'状态
this.showCard(true, 'recorded');
......@@ -1013,12 +1031,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
},
"tokenId": "632be7a73327935c2b000005"
}
if (!courseware) return this.recrodEnd(testData)
if (!courseware) {
await this.recrodEnd(testData)
resolve(testData);
return;
}
// await pg.time.delay(5);
courseware && courseware.stopTest((data) => {
courseware && courseware.stopTest(async (data) => {
data = JSON.parse(data);
this.recrodEnd(data);
await this.recrodEnd(data);
resolve(data);
}); //结束录音
})
}
onTouchPlayRecord() {
const voice = Game.getIns().player.getLastVoice();
......@@ -1091,28 +1115,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
await pg.time.delay(2);
this.updateTips(null);
return;
} else {
// 单词不正确
if (this.tryData.some(td => td.id == this.touchData.id)) {
// 已经尝试过的题目,显示加油提示
this.updateTips(TIPS_STATE.COMEON);
if (this.tryAgain) {
// 第二次尝试后,无论结果如何都进入下一题
this.tryAgain = false;
// 如果有父节点(火苗节点),隐藏它
if (this.touchData && this.touchData.parent) {
this.touchData.parent.active = false;
}
await pg.time.delay(3);
this.showCard(false);
this.updateTips(null);
this.recordTouching = false;
this.onRecordFail();
return;
}
} else {
// 首次尝试失败,显示再试一次提示
this.updateTips(TIPS_STATE.TRYAGAIN);
......@@ -1123,7 +1125,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (this.touchData && this.touchData.parent && !this.activeNodes.includes(this.touchData.parent)) {
this.activeNodes.push(this.touchData.parent);
}
}
Game.getIns().player.addVoice(data);
}
// 延迟后隐藏提示
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment