I try to make a dictation-program for my pupils in this coronatimes. The work is almost done, but I am confronted with the following problem:
The program selects every time a random word from a list of 3630 words. Normally, you preload the assets in the preload function as in this example . But this is difficult with 3630 words. I know it’s possible to pack all the word in one audiofile, but that’s not a solution, because it takes too long to load this file.
With the help of Telinc1 I’ve found the solution, but now I’m faced with the problem I can only hear each word once. When I click the second time on a word, I can’t hear it. I hope there is a solution for this problem. Thanks anyway to look at my problem.
After a sound has loaded once, it’s kept in memory, so the loader will simply ignore it when you try to load it again. The solution is to skip the loader in listenWord
if the sound has already been loaded:
if(this.cache.audio.has(myWord)) {
// playSound is declared as taking two arguments, but it doesn't use the second one.
this.playSound(myWord);
} else {
// load the sound normally
}
Another problem that you probably haven’t noticed is that the calls to playSound
get duplicated for each sound that loads. This is because you register a new event listener every time you want to play one sound. You can either register the event listener once when the scene starts, or register a one-time event listener from listenWord
with this.load.once("filecomplete", ...)
.
You are my hero. I try this solution tomorrow!
Its’ working, thank you so much for the second time.
Up to the next problem