WebGL - Streaming of 'ogg' on this platform is not supported

I’ve got an .ogg file up on the server that I’d like to download and play at runtime. I’ve got some code that works in the editor, but doesn’t work in a WebGL deploy. In the WebGL deploy, I get the following error:

Streaming of ‘ogg’ on this platform is not supported.

Well, I’m not trying to stream it. In fact I’d prefer for the audio to be fully downloaded before attempting playback.

Here’s the code I’m testing with:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class test_dynamic_audio : MonoBehaviour
{
	public Text txt_message;

	private AudioSource _source;

	// Use this for initialization
	IEnumerator Start()
	{
		string url;

		url = "http://www.domain.com/url/to/audio.ogg";

		_source = GetComponent<AudioSource>();

		yield return new WaitForSeconds(0.5f);

		WWW www = new WWW(url);
		yield return www;

		_source.clip = www.GetAudioClip(false, false, AudioType.OGGVORBIS);

		yield return new WaitForSeconds(0.5f);
		
		_source.Play();
	}
	
	// Update is called once per frame
	void Update()
	{
		txt_message.text = "LOADING...";

		if (_source.clip != null)
		{
			txt_message.text = "LOADED.";

			if (_source.clip.isReadyToPlay)
			{
				if (_source.isPlaying)
				{
					txt_message.text = "PLAYING.";
				}
			}
		}
	}
}

Any ideas on how to properly download audio and play it in WebGL?

So after further trial and error, we determined that .ogg files don’t download properly at runtime in WebGL deploys, but .mp3 files do. Converting all of our .oggs to .mp3s have resolved this issue.

There is a trick to make .ogg files to download and behave correctly, when you are running your Unity WebGL application on an actual web browser.

Use the following audio type enum value.

AudioType.AUDIOQUEUE

But when you are not running your Unity WebGL application on any web browser, for example if you are running it inside the Unity editor, then with .ogg files you do need to use the following audio type enum value.

AudioType.OGGVORBIS