- Home /
Replacing AudioSource with an audio from file
Hi,
I'm trying to have an audio file (.ogg) downloaded from my server using WWW and then have the audio file replace one of my AudioSources for one of my game object.
I can successfully download the file to Application.persistentDataPath, but couldn't figure out how I could assign it to the AudioSource.
I tried the following but had no luck:
private AudioClip mAudio;
WWW requestAudio = new WWW ("[webAddress]/0.ogg");
yield return requestAudio;
File.WriteAllBytes (Application.persistentDataPath + "/0.ogg", requestAudio.bytes);
mAudio = requestAudio.audioClip;
myObject.transform.GetComponentInChildren<AudioSource>().clip = mAudio;
Could someone please show me a way in how I could achieve that?
Thanks so much!
hi,
about this line:
myObject.transform.GetComponentInChildren<AudioSource>().clip = mAudio;
I think you are going to far :p
you just need to have an AudioSource attached to myObject, then you can do :
audio.clip = mAudio;
and if you want to play it:
audio.Play();
regards
Your answer
Follow this Question
Related Questions
WWW Audio and PlayOneShot: Playing the same AudioClip Twice Cuts off First Instance 1 Answer
Use hardware decoding when loading an audio file via WWW 1 Answer
Stream audio from a YouTube playlist's URL? 0 Answers
How do i stream music from a server? 0 Answers
Get AudioClip from Path?,How to get AudioClip from a path? 1 Answer