Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
SSAPP2502
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
SSAPP2502
Commits
94759aba
Commit
94759aba
authored
Aug 13, 2025
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(语音功能): 修复语音按钮点击和录音关闭逻辑问题
parent
d6b97261
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
129 additions
and
129 deletions
+129
-129
SSAPP2502.fire
assets/SSAPP2502/scene/SSAPP2502.fire
+7
-9
SSAPP2502.ts
assets/SSAPP2502/scene/SSAPP2502.ts
+122
-120
No files found.
assets/SSAPP2502/scene/SSAPP2502.fire
View file @
94759aba
...
@@ -1353,9 +1353,7 @@
...
@@ -1353,9 +1353,7 @@
"__id__": 25
"__id__": 25
},
},
"_enabled": true,
"_enabled": true,
"_clip": {
"_clip": null,
"__uuid__": "8bbf063f-fd82-4e2c-b54d-0997b6004b2c"
},
"_volume": 1,
"_volume": 1,
"_mute": false,
"_mute": false,
"_loop": false,
"_loop": false,
...
@@ -1434,9 +1432,7 @@
...
@@ -1434,9 +1432,7 @@
"__id__": 27
"__id__": 27
},
},
"_enabled": true,
"_enabled": true,
"_clip": {
"_clip": null,
"__uuid__": "36ab29df-0eff-40ad-bd25-daa3d15f55cd"
},
"_volume": 1,
"_volume": 1,
"_mute": false,
"_mute": false,
"_loop": false,
"_loop": false,
...
@@ -3758,7 +3754,7 @@
...
@@ -3758,7 +3754,7 @@
"__id__": 111
"__id__": 111
}
}
],
],
"_active":
fals
e,
"_active":
tru
e,
"_components": [
"_components": [
{
{
"__id__": 113
"__id__": 113
...
@@ -4485,8 +4481,10 @@
...
@@ -4485,8 +4481,10 @@
"_fontSize": 130,
"_fontSize": 130,
"_lineHeight": 130,
"_lineHeight": 130,
"_enableWrapText": false,
"_enableWrapText": false,
"_N$file": null,
"_N$file": {
"_isSystemFontUsed": true,
"__uuid__": "23f9661e-5c67-41a5-abdf-65a4b99ef31b"
},
"_isSystemFontUsed": false,
"_spacingX": 0,
"_spacingX": 0,
"_batchAsBitmap": false,
"_batchAsBitmap": false,
"_styleFlags": 0,
"_styleFlags": 0,
...
...
assets/SSAPP2502/scene/SSAPP2502.ts
View file @
94759aba
...
@@ -692,6 +692,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -692,6 +692,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
renderProgressLabel
(
label_progress
);
this
.
renderProgressLabel
(
label_progress
);
}
}
onTouchVoice
()
{
// 使用pg.ts的API播放音频
const
currentData
=
this
.
currentTouchNode
.
data
;
pg
.
audio
.
playAudioByUrl
(
currentData
.
audioUrl
);
}
/**
/**
* 处理语音按钮的显示和事件绑定
* 处理语音按钮的显示和事件绑定
* @param btn_voice 语音按钮节点
* @param btn_voice 语音按钮节点
...
@@ -702,10 +707,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -702,10 +707,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 如果数据中有audio,显示语音按钮
// 如果数据中有audio,显示语音按钮
pg
.
view
.
visible
(
btn_voice
,
true
);
pg
.
view
.
visible
(
btn_voice
,
true
);
// 绑定点击事件播放音频
// 绑定点击事件播放音频
pg
.
view
.
touchOn
(
btn_voice
,
()
=>
{
pg
.
view
.
touchOn
(
btn_voice
,
this
.
onTouchVoice
,
this
);
// 使用pg.ts的API播放音频
pg
.
audio
.
playAudioByUrl
(
currentData
.
audioUrl
);
},
this
);
}
else
{
}
else
{
// 没有音频则隐藏按钮
// 没有音频则隐藏按钮
pg
.
view
.
visible
(
btn_voice
,
false
);
pg
.
view
.
visible
(
btn_voice
,
false
);
...
@@ -809,11 +811,26 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -809,11 +811,26 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
stopVoiceAni
();
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
);
this
.
showCard
(
false
);
// 获取最后一次录音数据
// 获取最后一次录音数据
const
lastVoice
=
Game
.
getIns
().
player
.
getLastVoice
();
const
lastVoice
=
Game
.
getIns
().
player
.
getLastVoice
();
if
(
lastVoice
.
questionId
!=
this
.
touchData
.
id
)
{
this
.
onRecordFail
();
return
;
}
// 如果有录音数据,则使用其分数
// 如果有录音数据,则使用其分数
if
(
lastVoice
&&
lastVoice
.
result
&&
lastVoice
.
questionId
==
this
.
touchData
.
id
)
{
if
(
lastVoice
&&
lastVoice
.
result
&&
lastVoice
.
questionId
==
this
.
touchData
.
id
)
{
const
score
=
lastVoice
.
result
.
overall
;
const
score
=
lastVoice
.
result
.
overall
;
...
@@ -935,6 +952,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -935,6 +952,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
* 停止倒计时,显示播放和重新录制按钮,结束录音
* 停止倒计时,显示播放和重新录制按钮,结束录音
*/
*/
private
onTouchRecordEnd
()
{
private
onTouchRecordEnd
()
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
// 使用更新后的showCard方法,传入'recorded'状态
// 使用更新后的showCard方法,传入'recorded'状态
this
.
showCard
(
true
,
'
recorded
'
);
this
.
showCard
(
true
,
'
recorded
'
);
...
@@ -1013,12 +1031,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -1013,12 +1031,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
},
},
"
tokenId
"
:
"
632be7a73327935c2b000005
"
"
tokenId
"
:
"
632be7a73327935c2b000005
"
}
}
if
(
!
courseware
)
return
this
.
recrodEnd
(
testData
)
if
(
!
courseware
)
{
await
this
.
recrodEnd
(
testData
)
resolve
(
testData
);
return
;
}
// await pg.time.delay(5);
// await pg.time.delay(5);
courseware
&&
courseware
.
stopTest
(
(
data
)
=>
{
courseware
&&
courseware
.
stopTest
(
async
(
data
)
=>
{
data
=
JSON
.
parse
(
data
);
data
=
JSON
.
parse
(
data
);
this
.
recrodEnd
(
data
);
await
this
.
recrodEnd
(
data
);
resolve
(
data
);
});
//结束录音
});
//结束录音
})
}
}
onTouchPlayRecord
()
{
onTouchPlayRecord
()
{
const
voice
=
Game
.
getIns
().
player
.
getLastVoice
();
const
voice
=
Game
.
getIns
().
player
.
getLastVoice
();
...
@@ -1091,28 +1115,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -1091,28 +1115,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
await
pg
.
time
.
delay
(
2
);
await
pg
.
time
.
delay
(
2
);
this
.
updateTips
(
null
);
this
.
updateTips
(
null
);
return
;
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
{
}
else
{
// 首次尝试失败,显示再试一次提示
// 首次尝试失败,显示再试一次提示
this
.
updateTips
(
TIPS_STATE
.
TRYAGAIN
);
this
.
updateTips
(
TIPS_STATE
.
TRYAGAIN
);
...
@@ -1123,7 +1125,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -1123,7 +1125,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
if
(
this
.
touchData
&&
this
.
touchData
.
parent
&&
!
this
.
activeNodes
.
includes
(
this
.
touchData
.
parent
))
{
if
(
this
.
touchData
&&
this
.
touchData
.
parent
&&
!
this
.
activeNodes
.
includes
(
this
.
touchData
.
parent
))
{
this
.
activeNodes
.
push
(
this
.
touchData
.
parent
);
this
.
activeNodes
.
push
(
this
.
touchData
.
parent
);
}
}
}
Game
.
getIns
().
player
.
addVoice
(
data
);
}
}
// 延迟后隐藏提示
// 延迟后隐藏提示
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment