I have a little piano game where the user can touch piano keys to play the a piano key and hear a note sound. Additionally, the user can press a button that makes the piano play a sound on its own. Playing a note also plays a key up and down animation.
My implementation has 16 audio sources. Each piano key press looks for an audio source not running and then uses it. The audio sources are created in the Unity editor and put on the GameObject.
My problem: occasionally notes do not play. From debug I know an audiosource has been selected and plays the note audioClip. Before isPlaying is false, and after isPlaying is true but no sound occurs. The associated animation always works. It can happen on the second note played or the nth. It seems more likely to happen in certain sequences but not reliably. I am not a fan of non-repeatable bugs.
This happen in Windows and on the Android device making is appear to be a Unity issue.
My code.
AudioSource audioSource = nextPlayOnceSource(); // get an AudioSource
audioSource.clip = clip;
audioSource.Play();
I have also tried
AudioSource audioSource = nextPlayOnceSource();
audioSource.PlayOneShot(clip);
Any ideas on what could be wrong or other things for me to experiment with are greatly appreciated.