优化playAudio,之后onerror不会addVideo,以防止可能的内存泄漏
This commit is contained in:
parent
e05e689556
commit
6f2d0e7838
|
@ -1364,19 +1364,21 @@ export class Game extends Uninstantable {
|
|||
else if (!path.startsWith('db:')) path = `audio/${path}`;
|
||||
if (!lib.config.repeat_audio && _status.skillaudio.includes(path)) return;
|
||||
}
|
||||
_status.skillaudio.add(path);
|
||||
game.addVideo('playAudio', null, path);
|
||||
setTimeout(() => _status.skillaudio.remove(path), 1000);
|
||||
const audio = document.createElement('audio');
|
||||
audio.autoplay = true;
|
||||
audio.volume = lib.config.volumn_audio / 8;
|
||||
audio.addEventListener('ended', () => audio.remove());
|
||||
audio.onerror = event => {
|
||||
//Some browsers do not support "autoplay", so "oncanplay" listening has been added
|
||||
audio.oncanplay = () => Promise.resolve(audio.play()).catch(() => void 0);
|
||||
audio.onplay = () => {
|
||||
_status.skillaudio.add(path);
|
||||
setTimeout(() => _status.skillaudio.remove(path), 1000);
|
||||
game.addVideo("playAudio", null, path);
|
||||
};
|
||||
audio.onended = (event) => audio.remove();
|
||||
audio.onerror = (event) => {
|
||||
audio.remove();
|
||||
if (onError) onError(event);
|
||||
};
|
||||
//Some browsers do not support "autoplay", so "oncanplay" listening has been added
|
||||
audio.oncanplay = () => Promise.resolve(audio.play()).catch(() => void 0);
|
||||
new Promise((resolve, reject) => {
|
||||
if (path.startsWith('db:')) game.getDB('image', path.slice(3)).then(octetStream => resolve(get.objectURL(octetStream)), reject);
|
||||
else if (lib.path.extname(path)) resolve(`${lib.assetURL}${path}`);
|
||||
|
|
|
@ -2025,10 +2025,10 @@ export const Content = {
|
|||
event.choice = event.doing.todoList.filter(info => {
|
||||
if (!lib.filter.filterTrigger(trigger, info.player, event.triggername, info.skill)) return false;
|
||||
if (directUse(info)) return false;
|
||||
if (event.current.priority !== info.priority) return false;
|
||||
if (event.current.player !== info.player) return false;
|
||||
return lib.skill.global.includes(info.skill) || event.current.player.hasSkill(info.skill, true);
|
||||
});
|
||||
event.choice = event.choice.filter(n=>n.priority == event.choice[0].priority);
|
||||
if (event.choice.length < 2) return event.goto(4);
|
||||
'step 2';
|
||||
const next = event.choice[0].player.chooseControl(event.choice.map(i => i.skill));
|
||||
|
|
Loading…
Reference in New Issue