Skip to content

Commit 9d98865

Browse files
Merge pull request #764 from xiaoxustudio/fix/playEffect-playback-and-auto-play
fix: automatic playback to fail when play audio for not exist file
2 parents a2109ba + 846c423 commit 9d98865

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/webgal/src/Core/gameScripts/playEffect.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { IPerform } from '@/Core/Modules/perform/performInterface';
66
import { useSelector } from 'react-redux';
77
import { WebGAL } from '@/Core/WebGAL';
88
import { WEBGAL_NONE } from '@/Core/constants';
9+
import { end } from './end';
910

1011
/**
1112
* 播放一段效果音
@@ -91,7 +92,7 @@ export const playEffect = (sentence: ISentence): IPerform => {
9192
};
9293
resolve(perform);
9394
seElement?.play();
94-
seElement.onended = () => {
95+
const endFunc = () => {
9596
for (const e of WebGAL.gameplay.performController.performList) {
9697
if (e.performName === performInitName) {
9798
isOver = true;
@@ -100,6 +101,12 @@ export const playEffect = (sentence: ISentence): IPerform => {
100101
}
101102
}
102103
};
104+
seElement.onended = endFunc;
105+
seElement.addEventListener('error', (e) => {
106+
logger.error(`播放效果音失败: ${url}`);
107+
// 播放失败提前结束
108+
endFunc();
109+
});
103110
}, 1);
104111
}),
105112
};

0 commit comments

Comments
 (0)