Commit 5639b3a2 authored by Tt's avatar Tt

fix(play): 修复音频播放问题并更新默认音频URL

parent d64bc800
...@@ -56,7 +56,7 @@ let defaultFormData: FormData = { ...@@ -56,7 +56,7 @@ let defaultFormData: FormData = {
imgSize: 'big', imgSize: 'big',
"questions": [ "questions": [
{ {
"type": "txt", "audio": "http://staging-teach.cdn.ireadabc.com/736c616e8b66a3ae03c8e8636ca46f0f.mp3", "text": "", "image": "http://staging-teach.cdn.ireadabc.com/bde25b1b2a7fdf976f17ae80b6a20a25.png", "time": null, "duration": "", "audioName": "", "imgSize": "big" "type": "txt", "audio": "https://staging-teach.cdn.ireadabc.com/a050401ba53e74ede17b5c49635a977a.mp3", "text": "", "image": "http://staging-teach.cdn.ireadabc.com/bde25b1b2a7fdf976f17ae80b6a20a25.png", "time": null, "duration": "", "audioName": "", "imgSize": "big"
}, { }, {
"type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/89060c9eddd5f0f67908cce77ee74f94.mp3", "image": "http://staging-teach.cdn.ireadabc.com/761e1b17e16fa4674db9ad5344676bb9.png", "time": null, "audioName": "" "type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/89060c9eddd5f0f67908cce77ee74f94.mp3", "image": "http://staging-teach.cdn.ireadabc.com/761e1b17e16fa4674db9ad5344676bb9.png", "time": null, "audioName": ""
}, { }, {
...@@ -1014,10 +1014,12 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1014,10 +1014,12 @@ export class PlayComponent implements OnInit, OnDestroy {
if (currentQuestion.correctQuestion && currentQuestion.correctQuestion.audio) { if (currentQuestion.correctQuestion && currentQuestion.correctQuestion.audio) {
if ((this.g_formData.doubleModal || this.currentStageIndex !== 0)) { if ((this.g_formData.doubleModal || this.currentStageIndex !== 0)) {
setTimeout(() => { setTimeout(() => {
this.g_cartoon.playAudio(currentQuestion.correctQuestion.audio); this.g_cartoon.stopAllAudio();
this.g_cartoon.playAudio(currentQuestion.correctQuestion.audio, true);
}, 500); }, 500);
} else { } else {
this.g_cartoon.playAudio(currentQuestion.correctQuestion.audio); this.g_cartoon.stopAllAudio();
this.g_cartoon.playAudio(currentQuestion.correctQuestion.audio, true);
} }
} }
} }
...@@ -1059,7 +1061,8 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1059,7 +1061,8 @@ export class PlayComponent implements OnInit, OnDestroy {
const currentStage = this.gameStages[this.currentStageIndex]; const currentStage = this.gameStages[this.currentStageIndex];
if (currentStage && currentStage.correctQuestion && currentStage.correctQuestion.audio) { if (currentStage && currentStage.correctQuestion && currentStage.correctQuestion.audio) {
// 播放当前正确问题的音频 // 播放当前正确问题的音频
this.g_cartoon.playAudio(currentStage.correctQuestion.audio); this.g_cartoon.stopAllAudio();
this.g_cartoon.playAudio(currentStage.correctQuestion.audio, true);
} }
// 注销该鱼的点击事件 // 注销该鱼的点击事件
this.unsubscribeFishEvent(fish.fishId); this.unsubscribeFishEvent(fish.fishId);
...@@ -1931,7 +1934,8 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1931,7 +1934,8 @@ export class PlayComponent implements OnInit, OnDestroy {
console.log("btn_fa_yin", currentStage) console.log("btn_fa_yin", currentStage)
if (currentStage && currentStage.correctQuestion && currentStage.correctQuestion.audio) { if (currentStage && currentStage.correctQuestion && currentStage.correctQuestion.audio) {
// 播放当前正确问题的音频 // 播放当前正确问题的音频
this.g_cartoon.playAudio(currentStage.correctQuestion.audio); this.g_cartoon.stopAllAudio();
this.g_cartoon.playAudio(currentStage.correctQuestion.audio, true);
} }
}) })
} }
...@@ -2848,15 +2852,15 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -2848,15 +2852,15 @@ export class PlayComponent implements OnInit, OnDestroy {
// 帧率控制:计算当前时间与上一帧时间的差值 // 帧率控制:计算当前时间与上一帧时间的差值
const currentTime = Date.now(); const currentTime = Date.now();
const elapsed = currentTime - this.m_lastFrameTime; const elapsed = currentTime - this.m_lastFrameTime;
// 计算时间增量(秒) // 计算时间增量(秒)
const dt = elapsed / 1000; const dt = elapsed / 1000;
// 如果经过的时间小于帧间隔,则跳过本次更新 // 如果经过的时间小于帧间隔,则跳过本次更新
if (elapsed < this.m_frameInterval) { if (elapsed < this.m_frameInterval) {
return; return;
} }
// 如果时间间隔过大(大于0.1秒),说明可能是后台运行或性能问题,限制最大时间增量 // 如果时间间隔过大(大于0.1秒),说明可能是后台运行或性能问题,限制最大时间增量
// 避免因为大的时间间隔导致渲染异常 // 避免因为大的时间间隔导致渲染异常
if (dt > 0.1) { if (dt > 0.1) {
...@@ -2937,7 +2941,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -2937,7 +2941,7 @@ export class PlayComponent implements OnInit, OnDestroy {
private isGameStart = false; private isGameStart = false;
private currentFishIndex = 0; private currentFishIndex = 0;
private m_fishTimeAccumulator = 0; // 累积的时间,用于鱼的生成 private m_fishTimeAccumulator = 0; // 累积的时间,用于鱼的生成
updateFish(dt: number = 0) { updateFish(dt: number = 0) {
// 如果没有游戏阶段或当前阶段索引超出范围,不生成鱼 // 如果没有游戏阶段或当前阶段索引超出范围,不生成鱼
if (!this.gameStages || this.currentStageIndex >= this.gameStages.length) { if (!this.gameStages || this.currentStageIndex >= this.gameStages.length) {
...@@ -2950,7 +2954,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -2950,7 +2954,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// 累积时间,用于鱼的生成 // 累积时间,用于鱼的生成
this.m_fishTimeAccumulator += dt * 1000; // 转换为毫秒 this.m_fishTimeAccumulator += dt * 1000; // 转换为毫秒
// 使用累积的时间来控制鱼的生成频率,从而间接控制屏幕上的鱼的数量 // 使用累积的时间来控制鱼的生成频率,从而间接控制屏幕上的鱼的数量
if (this.m_fishTimeAccumulator >= this.m_fishInterval) { if (this.m_fishTimeAccumulator >= this.m_fishInterval) {
// 创建新的鱼 // 创建新的鱼
...@@ -2999,7 +3003,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -2999,7 +3003,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// 鱼的基础速度是每秒60像素(1像素/帧 * 60帧/秒) // 鱼的基础速度是每秒60像素(1像素/帧 * 60帧/秒)
const baseSpeed = 60; // 每秒移动的像素数 const baseSpeed = 60; // 每秒移动的像素数
const moveDistance = baseSpeed * dt * fish.speed; const moveDistance = baseSpeed * dt * fish.speed;
// 向左移动鱼 // 向左移动鱼
fish.ref.x -= moveDistance; fish.ref.x -= moveDistance;
......
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