Commit ec2255ab authored by Tt's avatar Tt

app

parent 524f2cd2
This diff is collapsed.
......@@ -673,6 +673,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 设置进度显示
this.renderProgressLabel(label_progress);
}
onTouchVoice() {
// 使用pg.ts的API播放音频
const currentData = this.currentFireNode.data;
pg.audio.playAudioByUrl(currentData.audioUrl);
}
/**
* 处理语音按钮的显示和事件绑定
......@@ -684,10 +689,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);
......@@ -791,7 +793,17 @@ 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);
// 获取最后一次录音数据
......@@ -934,6 +946,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
* 停止倒计时,显示播放和重新录制按钮,结束录音
*/
private onTouchRecordEnd() {
return new Promise(async (resolve, reject) => {
// 使用更新后的showCard方法,传入'recorded'状态
this.showCard(true, 'recorded');
......@@ -943,7 +956,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 重置录音开始时间
this.recordStartTime = 0;
let testData = {
let testData: any = {
"audioUrl": "https://staging-teach.cdn.ireadabc.com/a8ea7bb153a46941e6f28b7d0dda49f4.mp3",
"eof": 1,
"file": "/storage/emulated/0/Android/data/com.example.oxford/cache/shengtong/gradeVoice.mp3",
......@@ -952,7 +965,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
"fluency": 84,
"integrity": 100,
"kernel_version": "3.7.1",
"overall": 8,
"overall": 11,
"pronunciation": 88,
"resource_version": "2.3.11",
"rhythm": 46,
......@@ -1012,12 +1025,56 @@ export default class SceneComponent extends MyCocosSceneComponent {
},
"tokenId": "632be7a73327935c2b000005"
}
if (!courseware) return this.recrodEnd(testData)
testData = {
"audioUrl": "http://staging-teach.cdn.ireadabc.com/oxford_voice/b24a6c27b9ff2557/1754926351482.mp3",
"eof": 1,
"file": "/storage/emulated/0/Android/data/com.example.oxford/cache/shengtong/gradeVoice.mp3",
"result": {
"duration": "2.350",
"fluency": 0,
"integrity": 0,
"kernel_version": "3.7.1",
"overall": 0,
"pronunciation": 0,
"resource_version": "2.3.12",
"rhythm": 0,
"sentences": [
{
"beginIndex": 0,
"details": [
{
"charType": 0,
"end": 0,
"overall": 0,
"prominence": 0,
"start": 0,
"word": "hat"
}
],
"end": 0,
"endIndex": 0,
"overall": 0,
"sentence": "hat",
"start": 0
}
],
"speed": 0
},
"tokenId": "689a0d0c332793307e000004",
"questionId": 5
}
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 +1148,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.onFireFail();
return;
}
} else {
// 首次尝试失败,显示再试一次提示
this.updateTips(TIPS_STATE.TRYAGAIN);
......@@ -1123,7 +1158,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (this.touchData && this.touchData.parent && !this.activeFireNodes.includes(this.touchData.parent)) {
this.activeFireNodes.push(this.touchData.parent);
}
}
Game.getIns().player.addVoice(data);
}
// 延迟后隐藏提示
......
......@@ -1017,6 +1017,53 @@ let pg = {
const id = cc.audioEngine.playEffect(audio.clip, loop);
resolve(id);
})
},
/**
* 显示提示信息
* @param {string} message - 提示信息内容
*/
showToast(message) {
console.log("show toast->" + message);
// 创建一个临时节点显示提示信息
const canvas = cc.director.getScene().getChildByName('Canvas');
if (!canvas) return;
// 创建提示节点
const node = new cc.Node('Toast');
canvas.addChild(node);
node.setPosition(0, 0);
node.zIndex = 999;
// 创建背景
const bg = new cc.Node('ToastBg');
node.addChild(bg);
const bgGraphics = bg.addComponent(cc.Graphics);
bgGraphics.fillColor = cc.Color.BLACK;
bgGraphics.lineWidth = 0;
bgGraphics.roundRect(-200, -30, 400, 60, 10);
bgGraphics.fill();
// 创建文本
const label = new cc.Node('ToastLabel');
node.addChild(label);
const labelComp = label.addComponent(cc.Label);
labelComp.string = message;
labelComp.fontSize = 24;
labelComp.lineHeight = 24;
labelComp.horizontalAlign = cc.Label.HorizontalAlign.CENTER;
labelComp.verticalAlign = cc.Label.VerticalAlign.CENTER;
// 动画显示和消失
node.opacity = 0;
const fadeIn = cc.fadeTo(0.3, 255);
const delay = cc.delayTime(1.5);
const fadeOut = cc.fadeTo(0.3, 0);
const remove = cc.callFunc(() => {
node.removeFromParent(true);
node.destroy();
});
node.runAction(cc.sequence(fadeIn, delay, fadeOut, remove));
}
},
/**
......
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