Issue with AudioEngine on android

Since simple audio engine was giving issue, I added code for AudioEngine and made it work. However in a particular scenario, when I try to play one audio effect, 2 audio effects get played (the current one and the one that was played before). This occurs only on android and works fine on windows and ios.

I should also mention that so far this occurs only when 2 audio clips are played in sequence.
I mean when a.mp3 gets played after b.mp3, both a.mp3 and b.mp3 get played at the same time.

code to play audio is as follows

int AudioWrapper::playAudio(string path, bool loop, bool isBackground)
{
#if shouldUseOldEngine

	if(isBackground)
	{
		SimpleAudioEngine::getInstance()->playBackgroundMusic(path.c_str(), loop);
		return 1;
	}
	else
	{
		return SimpleAudioEngine::getInstance()->playEffect(path.c_str(), loop);
	}

#else
	
	if (isBackground)
	{
		backgroundId = AudioEngine::play2d(path.c_str(), loop, isSoundOn ? 1.0f : 0.0f);

		return backgroundId;
	}
	else
	{
		return AudioEngine::play2d(path.c_str(), loop, isSoundOn ? 1.0f : 0.0f);
	}

#endif
}

What might be causing this weird bug ?

Probably an issue of delay to load files before playing.
Try using preload(...) method at launch for the first sound and see if it fixes your issue.

If you must have a sound play only after a previous one finishes you could look into using the setFinishCallback and pass in a lambda that tests for the correct AudioID of the first sound and then play the second from within that lambda (apparently it currently may delay 50ms after finished).

I have it preloaded already. Issue is not that audio plays with delay, issue is that previous audio plays again with the new audio.

Today I noticed that this bug is specific to Moto X Gen 2 (Android 6 ‘Marshmellow’) only.

What happens is when I play 1st audio clip and then play 2nd clip irrespective of the delay between those two clips, 1st clip plays again along with 2nd clip. This ONLY happens for those 2 particular audio clips and in that order.

I should also mention that the second audio clip was made by reversing the first clip.

I am completely stumped on this one.

Huh, strange, but not surprised as I’ve run into so many weird device or OS specific audio issues, and I know the team/forums/github-issues have as well. I hate dealing with audio on Android. /rant

So no two other clips behave in this manner?

I presume the reversed clip was done in an audio tool and exported as two separate files.
Have you tried a different audio format (ogg instead of wav, vice versa, or mp3/ogg depending?)

Yes, no two other clips behave in this manner. I did try to use the .ogg version of that audio clip. It still doesnt fix the issue.

Would it be wise to use SimpleAudioEngine for android and AudioEngine for IOS ? I am considering that option now.

You could try. It still seems like a bizarre bug such that if you haven’t already I would try to import the two clips into an audio editor and re-export into ogg and wav or whichever and try again.

That said if SimpleAudioEngine works for you, by all means use that on Android.