Blog

Unity3D WWW Audio

For some reason getting this set up was a terrible pain. Even the documentation for WWW.audioClip is obsolete. Not sure if this is the best method to download and play an audio file from the web, but it worked for me.

You want to have an Audio Source component on the game object you'll be using. Make sure the output on the audio source component is set correctly. Now make a new C# script. In my case, I named it WebAudio.

using UnityEngine;
using System.Collections;

public class WebAudio : MonoBehaviour
{
    
    public string url;
    WWW www;
    AudioClip clipFromWeb;
    
    IEnumerator Start ()
    {
        www = new WWW (url);
        yield return www;
        
        clipFromWeb = www.GetAudioClip (false);
        
        AudioSource source = GetComponent<AudioSource> ();
        source.clip = clipFromWeb;
        source.Play ();
    }
}

Make sure you've typed in the web address in the 'url' variable under your script in the inspector. The audio will not stream the audio, but begin playing after it was been downloaded.

I've only tested this with OGG files, so if you're trying to play WAV or MP3 files i'm not sure if it will work. 

Bobby FataComment