- Home /
Unity WebGL audio memory problem
Hi,
I am developing the application that can playback different audio files. Since Chrome disabled Web Player by default I am relying on WebGL. In my little demo I added 10 AudioClips in editor to my Custom Component and on Space press I playback them (25 MB each).
GetComponent<AudioSource>().clip = audios[j];
j++;
My files are 4 minutes long mp3 (also tried ogg) songs and after I reach 6-8 Web player crashes.
I use stripping level: Strip Assemblies, Explicitly thrown exceptions and non-development Fastest(very slow builds) settings. I am not using high end gaming hardware, but my desktop is relatively new and Unity runs without any lags (average pc of my target audience).
I tested with following memory settings: 256, 512, 1024. I actually don’t see any difference between 256 and 512, but 1024 is the worst – everything crashes after 2-3 audio.
Is there any way to achieve my goal?
Answer by bkachmar · Sep 02, 2015 at 06:11 PM
I figured out a way to solve that.
I developed a system in javascript to preload and play audio files and Unity just sends ExternalCall to javascript that says [preload audio "http://myaudios.com/1.mp3" at second "23"] and after CanPlayThrough event it says [play currently preloaded audio file].
By the way, chrome doesn't allow to preload more than 6 audios on one page, so you will need to reload audios all the time.