- Home /
Playing mp3 files on Android
I'm trying to play a single mp3 file in an Android app, I've tried the following code:
private AudioSource engine;
engine = gameObject.AddComponent<AudioSource>();
engine.playOnAwake = false;
engine.clip = (AudioClip)Resources.Load("mustangengine");
engine.volume = 1.0F;
engine.Play();
And nothing happens I mean I cannot listen any sound on the device and I don't get any errors, no exceptions, no nothing. I've imported the mustangengine.mp3 file using Assets->Import new Asset
What am I doing wrong? If the script code is wrong could you please tell me how to do it? Any other way would be fine as long as it works!
Thanks in advance for your help.
Answer by flamy · Feb 07, 2012 at 06:09 AM
Did you keep the mp3 file inside resource folder?? if you dont keep it there it is not goin to work .... because Resources.Load will seearch only in folders named resource not the whole project..
if you want to keep it anywhere and but still use it you have to declare a public variable of type AudioClip and link the specified file in editor... but if u want to laod at run time use Resources.Load because linking in editor means the file will always be there in memmory!!