SoundEffectInstance not working on Android

Hello forum!

I’ve read many of the issues surrounding SoundEffectInstances and SoundEffects.

I was able to get SoundEffects to work by installing the NuGet package (I had previously just installed 3.2 from the website).

However, SoundEffectInstances is still not working. I’ve tried using a .wav, .ogg and .xnb versions of the file. All of which were set as AndroidContent and Copy if Newer in the properties.

The SoundEffect is only 754 KB so size shouldn’t be an issue I wouldn’t think. Here’s the set up:

            fire = this.game.Content.Load<SoundEffect>("Sounds\\fire");
            fireInstance = fire.CreateInstance();
            fireInstance.IsLooped = true;
            fireInstance.Volume = .3f;
            fireInstance.Play();

I’ve tried adjusting the volume back up to 1 with no effect. This solution works just fine in Windows 8 and WP8.1 without an issue. The rest of the sounds work fine as well (i.e. the SoundEffect class and not SoundEffectInstance class).

I’m using Visual Studio 2012 on Windows 8.1 with MonoGame 3.2 installed along with XNA 4.0. The solution is using the Monogame Nuget Package as stated earlier. I also have the latest version of Xamarin for the android reference (v 2.3)

Anyone have ideas I can try?

Are there any exceptions being thrown in the debug window? I’ve had problems before on Android with sounds that have a non-standard sampling rate. I set all of my .wav files to 44.1kHz using GoldWave.

Thanks for the suggestion RocketRonz, I reduced the sampling rate to 44.1 kHz but that made no difference.

I did, however, figure it out. This is a case where Android behaves differently than WP8 and Windows Store (the game is published in those two places already).

In Android, if a SoundEffectInstance is paused (regardless of whether its playing or not) it will not Play upon calling .Play() You MUST call .Resume(). In WP8 and Windows (and most systems in real life) if a sound or song is paused, the play button would resume play!

My game pauses all sounds when the Main Menu is entered without checking to see if they are currently playing. I added a check on both the pause and play to invoke Resume when needed.

Thanks for the posting your solution!

I haven’t run into any issues but that’s because the sound fx I use are so short there’s no need to bother pausing them, they just die out anyway. I’m using 16bit 44.1khz WAVs on Android fine.

That’s good you managed to fix it :smile: My sounds are very short like BitBull’s, so I only ever need to call Play. 750kB is quite big for a sound effect so you could convert it to .mp3 and use the MediaPlayer class to play it. MediaPlayer is intended for game music and is a static class so you can only play one at a time, if you don’t have music then it might be worth using it to play your long sound effect.

Thanks again. The sound effect is looped so it’s effectively background noise (it’s a bonfire essentially). I may reduce the size but I want to leave the MediaPlayer open in case I decide to use actual music as well later on. Thanks for the help!

I have similar problem. SoundEffects doesnt play at all. they are small wav files. Tried converting to mp3, ogg, xnb with different compressions, wav 44100Hz 16bit - Notrhing works. Any ideas?

I have installed 3.2 from the website.
Visual studio 2013.

My trial to Xamarin.Android ended last night so at the moment I can’t even open the project to remember what I did to fix it!

Remove references to 3.2 that you downloaded via the website. Then, using nuget, add MonoGame to your project that way. If your game file is stilled called Game1.cs, back it up or rename it! (Actually, just back the whole thing up as a disclaimer).

My assumption is that the Nuget package is getting more frequent updates then the standalone website download.

Thx! Nuget package helped. (“Install-Package MonoGame”)