Load OGG Vorbis file from www at runtime

Hello. I want to load an .ogg vorbis file from a directory using www, but I just can’t seem to get it it work. Here is my code.

public static IEnumerator FetchAudio(SongData data, AudioSource source)
{
    DirectoryInfo dir = new DirectoryInfo(songsDirectory + "/" + data.directoryName);
    FileInfo[] info = dir.GetFiles(data.audioFileName);
    Debug.Log(info[0].FullName);
    WWW audio = new WWW(info[0].FullName);
    while (!audio.isDone)
    {
        Debug.Log("Progress: " + audio.progress);
        yield return audio;
    }

    Debug.Log("Progress: finished");
    AudioClip clip = WWWAudioExtensions.GetAudioClip(audio, true, true, AudioType.OGGVORBIS);
    if (clip != null) source.clip = clip;
}

In the console, it prints out the path of my file. It then prints “Progress: 0” just once. A few moments later, it prints “Progress: finished” immediately followed by an error with no text whatsoever - just an error symbol in the console. Someone please help me. I’ve spent the past 3 hours doing trial-error- google-try-again and I feel like I’m going insane.

@DJT4NN3R

I’ve also created a similar script a while ago where I had to “download” AudioClips from the local StreamingAssets folder with the WWW class and compared to your code I see several possible spots that may lead to this undesired behavior (wich I also had to fight against back then, so it may be adaptable to your scenario):

  1. Make sure to include the file extension at the end of the file path (line 3 - for example: " + data.directoryName + ".ogg"); ")
  2. In line 14, instead of deriving from WWWAudioExtensions try going directly from your audio variable, so audio.GetAudioClip(...);
  3. Maybe it helps to set the AudioType to .UNKNOWN, since it doesn’t seem to matter to be specific here

If none of that works, have a look at my code snippet and you might see what is missing (it works but as soon as I try to access an audio file that is not in the exact place specified in the filepath I also get the empty Error Warning; also interesting is that when I load that downloaded AudioClip into an Audio Source the Name of the AudioClip is also blank while playing the sound as usual, so it might be that the WWW class doesn’t apply the name of the file to it):