Some sounds fail to play on Android

About half of my audio files are failing to play on Android. They do work on windows and in the Unity Environment. I’m playing all of the audio the same way–something along the lines of:

go = new GameObject();
go.AddComponent<AudioSource>();
go.audio.clip = Resources.Load(somePath);        
go.audio.volume = 1;        
go.audio.Play();
  • The files are all coming from the same location.
  • They are all marked as 2D.
  • All of the failing sounds are *.WAV, though I do have working *.WAV as well.
  • *All of the failing .WAV are 89kbps bit rate. The working *.WAVs are 352kbps.
  • They are all marked as Form: Native (WAV) - Load Type: Load into memory.
  • If I set them to Audio Format: Compressed (MPEG) they DO work, but I’d like to know why.

Thanks!

I’m not an expert with Unity sounds, far from it but I have used them a lot without any significant problems like you are describing.

My first suggestion would be to just play the sounds differently. I’m not sure why you are creating a new Game Object and adding an Audio Source and then loading a clip from the resources every time you play a sound. That seems pretty excessive and I’m not sure why you would do it like that at run time. I’m assuming your Android device is having trouble doing all that fast enough for some of your files.

89KBPS is a very strange bitrate too. I’ve never seen that personally myself. Generally 128kbps seems to be the sweet spot for me when it comes to size vs quality. 352KBPS seems way too big especially for the way you are doing this on Android.

So I’m not sure how you are setting up these sounds like what objects they are attached too. But I think it’s a good idea to have one script attached to your camera that plays all the general game-play sounds/music. And then all your separate objects like consumables or enemies can have their own sounds on their script.

But I do it a lot differently than how you set it up, I’m not 100% sure but it seems like the way you are doing it is not optimal for slower devices.

I would recommend trying something like this to play your sounds:

//declare sound variables publicly
//can set them up super easy this way
//no need to create a new game object
//no need to create new audio source
//no need to load sounds so many times
//That advice is not factual just what I am assuming

//so you declare audio clip variable publicly
//this Game Object should already have 1 Audio Source
public AudioClip usePotionSound;

//when you want to play audio
//just call a function to play sound
//you already have gameobject, audioclip, and audiosource ready to go

public void usePotionSoundFunction()
{
audio.PlayOneShot(usePotionSound);
}

//If you want more control 
//you can do something like this
//to change settings on audio source
//for different clips

public AudioClip punchSound;

public AudioSource playerSkillsAudioSource;

public void playerPunchSoundFunction()
{
playerSkillsAudioSource.clip = punchSound;
playerSkillsAudioSource.minDistance = 10;
playerSkillsAudioSource.Play();
}

So I’m not 100% sure if this way is better than what you are doing. But it seems like it would be a lot better for mobile devices especially if you have all the sounds ready to go and loaded into memory instead of having to create a new game object and create new audio source and then load the resource.

You should also look into your bitrates both 89KBPS and 352KBPS seem a bit odd to me.

If these are short sound clips my understanding is that you should use .wav. For longer sounds like music that’s when you wanna use the compressed.

If you try my examples and it still doesn’t work maybe your Android device is just super slow or is running out of memory?

.mp3 Lame encoding works fine for me.