게임을 만들고 있는데 798 개의 사운드 파일을로드하고 싶지만 Chrome, Firefox에만 문제가 있습니다. 샘플 코드 : https://jsfiddle.net/76zb42ag/, 콘솔 참조 (F12 키 누름).크롬에 여러 개의 오디오 파일 (798)을 미리로드하십시오.
때로는 스크립트가 100, 500, 700 파일 만로드하는 경우가 있습니다. ex. 파일 수를 줄이면. 300은 괜찮습니다 (항상). 이 문제를 어떻게 해결할 수 있습니까? 콜백이나 아이디어가 필요해? 게임은 오프라인 상태가됩니다 (노드 웹킷).
자바 스크립트 코드 :
var total = 0;
// sample file to download: http://www.sample-videos.com/audio/mp3/crowd-cheering.mp3
// sounds.length = 798 files
var sounds = [
(...limit character, see https://jsfiddle.net/76zb42ag/...)
];
for (var i in sounds) {
load(sounds[i]);
}
function load(file) {
var snd = new Audio();
snd.addEventListener('canplaythrough', loadedAudio, false);
snd.src = file;
}
function loadedAudio() {
total++;
console.log(total);
if (total == sounds.length){
console.log("COMPLETE");
}
}
그건 슬프다.). – User9213