I added Beep.mp3 file to my project and set its type to RawResource. After build I can see id generated in R.Raws.Beep so I assume all is good. But when I try to use that resource and load sound into SoundPool instance I get an exception with a message "File res/raw/beep.mp3 from drawable resource ID #0x7f030000" and additionally in device log window I can see SoundPool logs "sample 0 not Founded" (really, that is how it says, "Founded"). I even checked content of apk file of my app and I can see res/raw/beep.mp3 is really there so seems that embedding resource in a package works and reason for an error is either in my code or I didn't do something else needed for it to work.
Reason for this file is a beep sound playing when user does something in my app so it is not like my own winamp clone or sth like that.
Ok, here is a code I execute and where I get an exception:
public static class SoundMaster
{
public static int BeepSoundId = 1;
private static readonly SoundPool SPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
private static readonly HashMap<int, int> SoundPoolMap = new HashMap<int, int>();
private static Context _context;
public static void InitSounds(Context context)
{
try
{
_context = context;
var loaded = SPool.Load(_context, R.Raws.Beep, 1);
SoundPoolMap.Put(BeepSoundId, loaded);
}
catch (Exception ex)
{
Log.E("InitSounds exception", ex.Message);
}
}
}
I call SoundMaster.InitSounds() method from my activity OnCreate method passing this as an argument so I believe it is perfectly correct Context instance.
One thing is that file embedded in apk is named beep.mp3 and actual file I included into project is Beep.mp3 but I tried multiple times with different names of file and resource id and always get same exception.
So can anybody share some thoughts on what might be a reason for my troubles with this code? or maybe I should use different ways to play my beep sound (MediaPlayer for example?) but I have a feeling code is correct and working but resources are messed up somehow.