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

2

0

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?

Wsan answered 16/10, 2023 at 7:15 Comment(0)
W
0

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.

Wsan answered 6/6, 2023 at 2:33 Comment(1)

Talking of oddities, I've faced with exactly the same issue. And that's inspite of "The data must be an audio clip in Ogg(Web/Standalones), MP3(phones) or WAV" from the official docs (https://docs.unity3d.com/ScriptReference/WWWAudioExtensions.GetAudioClip.html). Guess something was missed for some reason. Thanks for the solution!

Legit
P
0

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
Production answered 15/10, 2023 at 20:51 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.