I had the same problem - couldn't play sounds using neither SoundPool
nor MediaPlayer in apps built with NetBeans. I've found a solution
though and thought I'd share.

All you need to do is set 'keepcompression' attribute to 'true' on the
'zip' tag inside 'build-impl.xml' (can be found in the 'nbproject'
subdirectory). The 'zip' task is called from the '-package-dex'
target.

The problem is that although 'aapt' doesn't compress files with
extensions such as '.mp3', '.ogg', NetBeans uses 'zip' task to update
the APK archive with 'classes.dex' file along with other files (eg.
resources) which causes all files to be compressed.

Hope it helps.

On May 25, 9:36 pm, tony obrien <tobsourcecode...@gmail.com> wrote:
> The code:
> //this is all contained in my MainActivity.
>
>  private SoundPool soundPool;
>     private HashMap<Integer, Integer> soundPoolMap;
>     public static final int SOUND_CANNON = 1;
>     public static final int SOUND_HIT = 2;
>     public static final int SOUND_MISS = 3;
>     public static final int SOUND_WOUND = 4;
>     public static final int SOUND_TAUNT = 5;
>
>     private void initSounds() {
>
>         soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 100);
>         soundPoolMap = new HashMap<Integer, Integer>();
>         try {
>         soundPoolMap.put(SOUND_CANNON, soundPool.load(this,
> R.raw.cannon, 1) );
>         } catch(Exception e) {
>             String s = new String(e.getMessage());
>
>         }
>
>         soundPoolMap.put(SOUND_HIT, soundPool.load(this, R.raw.hit,
> 1));
>         soundPoolMap.put(SOUND_MISS, soundPool.load(this, R.raw.miss,
> 1));
>         soundPoolMap.put(SOUND_WOUND, soundPool.load(this,
> R.raw.wound, 1));
>         soundPoolMap.put(SOUND_TAUNT, soundPool.load(this,
> R.raw.taunt, 1));
>
>         }
>
> The Problem:
>
> soundPool.load fails indicating that the RESOURCE CANNOT BE FOUND.
>
> The oog files cannon, hit, miss, wound, and taunt are in my res/raw
> folder (I am using NetBeans with the Android 2.x Emulator, BTW)
> As an experiment I have added a line to try to open the same resource
> (i.e. via the R.raw.xxx  ID) as an InputStream and that succeeds. So I
> am stumped as to why won't load as a soundPool resource.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to