Issue
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.
Solution
The exception is caused because of an issue in the APK packager of dot42. It should not compress some resources (based on known extensions of already compressed files).
We could reproduce the problem with the current dot42 version. When excluding .mp3 from compression the problem was solved. We'll add the correct list of extensions now. This fix will be in the next update. (Update 1.0.1.74 on August 27 2013)
Disclosure, I work for dot42.
Answered By - Ewout Prangsma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.