Using SoundPool instead of MediaPlayer

All your problems with Audio, Video and Images.

Re: Still can't get SoundPool to work

Postby spirolateral » Wed Nov 26, 2008 4:38 pm

g1bb wrote:
g1bb wrote:Hello,

Java is not my fluent language, so please bear with me ;)

I've tried the following code after seeing the snippet here, and I can't seem to get this to work. Here's what I have:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class OneShotAlarm extends BroadcastReceiver
  2. {
  3.         private SoundPool soundPool;
  4.          private HashMap<Integer, Integer> soundPoolMap;
  5.          
  6.     @Override
  7.     public void onReceive(Context context, Intent intent)
  8.     {
  9.          soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
  10.          soundPoolMap = new HashMap<Integer, Integer>();
  11.          soundPoolMap.put(1, soundPool.load(context, R.raw.sound1, 1));
  12.        
  13.         AudioManager mgr = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
  14.         int streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
  15.         soundPool.play(soundPoolMap.get(1), streamVolume, streamVolume, 1, 0, 1f);
  16.     }
  17. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


You'll notice I replaced instaces of 'getContext()' with 'Context', as 'getContext()' doesn't seem to be available from where I have this code.

Here is my LogCat that's being returned, and no sound is being played:
11-08 19:25:23.679: DEBUG/dalvikvm(1822): Trying to load lib /system/lib/libsoundpool.so 0x0
11-08 19:25:23.759: DEBUG/dalvikvm(1822): Added shared lib /system/lib/libsoundpool.so 0x0
11-08 19:25:23.819: WARN/SoundPool(1822): sample 1 not READY

Any ideas on this? I've been pulling my hair out all day messing with MediaPlayer, then I came across SoundPool and it looks great!

Thanks in advance.


Got help with this. See this link for reference: http://groups.google.com/group/android- ... 2d3bc57537


i'm having this same problem, though i initialize my sounds well before i play them and i still get the "not ready" error sometimes. any idea how to tell if a sound is ready? and if it's not can i try to reload it?
spirolateral
Developer
Developer
 
Posts: 25
Joined: Tue Oct 14, 2008 5:15 am

Top

Postby txupete » Wed May 12, 2010 9:57 am

When I try to run on my emulator I have this error:

D/AndroidRuntime( 328): Shutting down VM
W/dalvikvm( 328): threadid=3: thread exiting with uncaught exception
(group=0x4001b188)
E/AndroidRuntime( 328): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime( 328): java.lang.RuntimeException: Unable to start
activity ComponentInfo{net.ikeralbeniz.fundroid/
net.ikeralbeniz.fundroid.MainActivity}: android.content.res.Resources
$NotFoundException: File res/raw/zas.mp3 from drawable resource ID
#0x7f04000a
E/AndroidRuntime( 328): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2454)
E/AndroidRuntime( 328): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2470)
E/AndroidRuntime( 328): at android.app.ActivityThread.access
$2200(ActivityThread.java:119)
E/AndroidRuntime( 328): at android.app.ActivityThread
$H.handleMessage(ActivityThread.java:1821)
E/AndroidRuntime( 328): at
android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 328): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 328): at
android.app.ActivityThread.main(ActivityThread.java:4310)
E/AndroidRuntime( 328): at
java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 328): at
java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 328): at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 328): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 328): at dalvik.system.NativeStart.main(Native
Method)
E/AndroidRuntime( 328): Caused by: android.content.res.Resources
$NotFoundException: File res/raw/zas.mp3 from drawable resource ID
#0x7f04000a
E/AndroidRuntime( 328): at
android.content.res.Resources.openRawResourceFd(Resources.java:859)
E/AndroidRuntime( 328): at
android.media.SoundPool.load(SoundPool.java:174)
E/AndroidRuntime( 328): at
net.ikeralbeniz.fundroid.MainActivity.onStart(MainActivity.java:53)
E/AndroidRuntime( 328): at
android.app.Instrumentation.callActivityOnStart(Instrumentation.java:
1129)
E/AndroidRuntime( 328): at
android.app.Activity.performStart(Activity.java:3723)
E/AndroidRuntime( 328): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2426)
E/AndroidRuntime( 328): ... 11 more
E/AndroidRuntime( 328): Caused by: java.io.FileNotFoundException:
This file can not be opened as a file descriptor; it is probably
compressed
E/AndroidRuntime( 328): at
android.content.res.AssetManager.openNonAssetFdNative(Native Method)
E/AndroidRuntime( 328): at
android.content.res.AssetManager.openNonAssetFd(AssetManager.java:411)
E/AndroidRuntime( 328): at
android.content.res.Resources.openRawResourceFd(Resources.java:856)
E/AndroidRuntime( 328): ... 16 more

I am using netbeans so I have edited de building xml to set -0 mp3 (or
-0 .mp3) to the aapt but nothing changed.. I still have the same
problem opening the mp3 files from raw.. any idea?
txupete
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Mar 22, 2010 1:05 pm

Top
Previous

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 12 guests