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();
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?
↧