- Home /
Loading OGG file, work in unity-editor, not outside
Hey,
im basicly loading 10 ogg files from a certain folder. That all works fine, playing them too. But when i pulbish my build and try it from there, the songs cant load. Doesnt even give errors and it does find the songs. Im really clueless.
try
{
string path = Application.dataPath;
path = path.Substring(0,path.LastIndexOf("/")) + "/Music";
allMusicClips = new ArrayList();
DirectoryInfo info = new DirectoryInfo(path);
fileInfo = info.GetFiles();
for (int i=0;i<fileInfo.Length;i++)
{
WWW www = new WWW("file://"+fileInfo[i].ToString());
StartCoroutine(FinishedLoadingSong(www));
}
}
catch (System.Exception e)
{
Debug.Log(e.ToString());
}
IEnumerator FinishedLoadingSong(WWW www)
{
yield return www;
AudioClip temp =www.GetAudioClip(true,true);
temp.name = www.url;
allMusicClips.Add(temp);
AbleToPlayMP3 = true;
}
Edit: code format is good now, sorry about that
Your script seems cut off, please, paste the whole script, and use the code sample format (the button with the 101 010) to make it readable.
What's your build target? The webplayer (and the mac and linux standalones, and the Android and iOS targets) have no access to a `G:` drive.
Have you copied the songs over to the data folder in the build? Application.dataPath in your unity project is not the same as Application.dataPath for your build. And I believe the songs would only copy with the project if you put them in the Resources folder.
Answer by Tarlius · Feb 28, 2013 at 06:57 AM
Since you seem to be using built in types (AudioClip), you will probably save yourself a lot of headaches if you do it "the unity way" and just put your songs in a Resource folder and use Resources.Load to load your assets.
Things will get more complicated if you need to add downloadable content/etc, but theres ways to get unity to do that for you too (AssetBundles)
I know, with resources it'd have been fixed easily. But i want the possibility to just put songs in a folder without needing to rebuild etc... It's odd that it's this complicated...
As long as you are aware the option exists. It can make life much easier. You can add after release with asset bundles, by the way.
Your answer

Follow this Question
Related Questions
Audio Track from Ogg Video File Doesn't Play 0 Answers
Multiple audiosources 1 Answer
Play AudioSource Backwards 2 Answers
AudioClip.Create crash on Mac OSX 1 Answer