"Unable to decode audio data" in webgl build
TL;DR Trying to build a WebGL project that runs in Chromium, an experimental build of chrome. The only sound compression formats that work in the build of Chromium I'm using are Vorbis, Opus, Wave, and OGA. How can I get Unity to use one of those compression formats for the build?
Hello, I'm relatively new to unity and have just started working on my first project. I'm trying to build something for WebGL and got to the point where I'm now adding sound, but I keep getting this error in my console in my browser:
Uncaught (in promise)
DOMException: Unable to decode audio data
I imported some free sound packages (links in asset store:UI sfx and casual game pack).
My build target is set to WebGL. When I go to the import settings for one of the sounds immediately after importing, there's a message in the inspector that says "The selection contains different compression formats to the default settings for the current build platform." Then, I check the box that says "Override for WebGL" and hit Apply, and then the warning message about different compression formats goes away.
Just as a test, I added an AudioSource to one of the objects in my scene, then dragged and dropped one of the sound files for which I checked the "Override for WebGL" into the AudioClip reference in the AudioSource, and checked "Play On Awake" and "Loop." When I try hitting play in the editor, I can hear the sound looping. When I build and try the project in my browser, though, I get the error above, the Unable to decode audio data one, in the console of my browser. I'm using Chromium (the experimental build of chrome) because I'm making a game that uses VR. For build template, I'm using the template found here, which is for handling the VR stuff.
For the sounds, I've tried using both .wav files and .mp3 files that I got from those free packages off of the asset store, and still none of them work.
For my webserver, I'm using mongoose.
So, does anyone know how I can do this correctly so that the sound will correctly play when built and run in a chromium? Thanks
UPDATE: So after spending some more time reading around and testing the build in other browsers, it turns out it's a problem specifically with Chromium, the experimental build of Chrome that supports WebVR. When I load the game in other browsers, the sounds play but the game doesn't run because no other browser supports both the WebVR AND the gamepad API that's needed to use the vive controllers.
I found this page that outlines what audio types are usable in Chromium, and so I've tried building the project when my sounds have a couple of different import settings. First, as I said, I've tried using the Override for WebGL setting which sets the compression format to AAC. I've also tried click the "Override for PC, Mac & Linux Standalone" instead, and from there I've tried Vorbis, PCM, and ADPCM compression formats as well. The page I linked that says which audio formats Chromium supports says it should support Vorbis, but I still get the "Unable to decode audio data" error, not matter which compression format I'm using.
SECOND UPDATE:
I found this site that tells you what audio file formats are supported on the browser you're in, and the build of Chromium that I'm using supports Vorbis and Wave. I've basically boiled down my question to: How can I get my build to have the Vorbis compression format for my audio files? I tried clicking the "Override for PC, Mac & Linux Standalone" and then selecting "Vorbis" as the compression format, but that still doesn't work. A friend suggested I try putting the audio files into the special "Resources" folder so that Unity doesn't try to compress it, which I'll try next, but I don't understand why it doesn't work when I select Vorbis when I know Vorbis works in my browser.