- Home /
WWW.audioClip not playing on android build
I'm referencing the Unity C# documentation here.
When using WWW.audioClip in the editor (Unity 5.4), it works fine (build is set to android). However, once I build and run the APK on an actual device, there is no sound. Other sounds work, but anything using WWW.audioClip won't work. I'm using mp3 files that I uploaded to a server to avoid using memory.
Sample url --> 159.203.212.244/music/kpop/haruHaru1.mp3
Code snippet:
void Start(){
// No changes made from unity docs here
// allClips is an array of strings (urls in the same form as above)
WWW www = new WWW (musicURLs.allClips[songCounter] );
source = GetComponent<AudioSource> ();
source.clip = www.audioClip;
}
// this is attached to a button, so that when you click it the clip will play
public void playMusicStream(){
// now play
if (!source.isPlaying && source.clip.isReadyToPlay)
source.Play ();
};
I have a domain name tied to the server address, so switching to http://preciousperfect.com/music/kpop/haruHaru1.mp3 would map to the same place (haven't tried this).
Thoughts:
The app already gets access to network privileges, so I don't think it's a problem with being allowed to access an external link.
I don't think it's an internal issue. I think I'm missing something and I'm doing this incorrectly, but I couldn't find anything about this online.
Any solutions/guidance will be greatly appreciated!
Update: I tried using .ogg files ins$$anonymous$$d and it had the same result. Still unsure of a solution
Answer by tomyhuang · Jan 03, 2019 at 08:12 PM
Have you tried yield turn www?
For example"
void Start() {
StartCoroutine(getAudio());
}
IEnumerator getAudio() {
WWW www = new WWW (musicURLs.allClips[songCounter] );
yield turn www; // it will wait for downloading music finished
source = GetComponent<AudioSource> ();
source.clip = www.audioClip;
}
Your answer
Follow this Question
Related Questions
Unload audio from external source 1 Answer
Distribute terrain in zones 3 Answers
Binary Save on android issues 1 Answer
Android build doesn't work 0 Answers
Do i need Android Studio or Xamarin? 2 Answers