- Home /
Play an array of audioclips from HDD.
I wanted to make a music player for my game which allows player to put his music into Music folder in game files and i have everything done, search for files -> make an array -> stream first track -> Play with audio source and the problem is that it does not play it, no sound after setting audio.clip and audio.Play() commands, no errors in compiler, any ideas? Thx in advance! Here's my code:
private var IsAnyMusicInFolder : boolean = false;
private var CheckMusicFolder : boolean = false;
private var ReadyToPlay : boolean = false;
private var MusicTrackID : float = 0;
function LoadMusicFromMusicFolder (){
var info = new DirectoryInfo(Application.dataPath+"/Music");
if (info == null){CheckMusicFolder = true;}else{
var fileInfo = info.GetFiles("*.ogg");
MusicFilesFromExtSrc = new WWW [fileInfo.length];
if (!CheckMusicFolder && fileInfo.length > 0){
for (i=0; i < fileInfo.length; i++){
var ExtMusicFile : WWW = new WWW (Application.dataPath+"/Music"+fileInfo[i]);
MusicFilesFromExtSrc[i] = ExtMusicFile;
print (MusicFilesFromExtSrc[i]);
}
IsAnyMusicInFolder = true; CheckMusicFolder = true;
} else {CheckMusicFolder = true;}
if (CheckMusicFolder && IsAnyMusicInFolder){
if (!audio.IsPlaying){
audio.clip = MusicFilesFromExtSrc[MusicTrackID].GetAudioClip(false, false);
audio.Play();
}
print (audio.clip);
}
}
}
It doesn't matter, AudioClip.GetAudioClip(); converts streamed audio to 2D audio.
Answer by Statement · Dec 10, 2012 at 10:55 PM
Try making a Coroutine that yield www; It looks like you have specified a file to steam/download but never initiated the download.
Actually, looking at the docs at http://docs.unity3d.com/Documentation/ScriptReference/WWW.GetAudioClip.html I see that it could use examples. If you come across places in the documentation that you can't find examples for, you could send a bug report via Unitys bug reporter and file a Documentation Bug Report. State what information is missing and our docs $$anonymous$$m will try and improve the information. But please make sure to set the bug type to documentation bug before you hit send!
http://answers.unity3d.com/questions/9292/how-do-i-report-a-bug-in-unity.html