Reputation: 3833
I wonder why my app crashes after loading and playing a soundfile exactly 482 times? On the 482:e click (listview) that loads and play a mp3 soundfile the following happends:
10-20 01:28:38.454: V/MediaPlayer(14307): decode(1018, 58494525, 47481)
10-20 01:28:40.424: I/System.out(14307): groupos i metoden getGroupId: 71
10-20 01:28:40.489: I/System.out(14307): groupos i metoden getGroupId: 71
10-20 01:28:40.489: V/SoundPoolThread(14307): Got message m=2, mData=480
10-20 01:28:40.489: V/MediaPlayer(14307): decode(1020, 58494525, 47481)
10-20 01:28:42.359: I/System.out(14307): groupos i metoden getGroupId: 71
10-20 01:28:42.424: I/System.out(14307): groupos i metoden getGroupId: 71
10-20 01:28:42.424: V/SoundPoolThread(14307): Got message m=2, mData=481
10-20 01:28:42.424: V/MediaPlayer(14307): decode(1022, 58494525, 47481)
10-20 01:28:44.244: I/System.out(14307): groupos i metoden getGroupId: 71
10-20 01:28:44.314: I/System.out(14307): groupos i metoden getGroupId: 71
10-20 01:28:44.314: V/SoundPoolThread(14307): Got message m=2, mData=482
10-20 01:28:44.314: V/MediaPlayer(14307): decode(-1, 58494525, 47481)
10-20 01:28:44.314: E/SoundPool(14307): Unable to load sample: (null)
10-20 01:28:44.324: W/SoundPool(14307): Sample was not loaded. Waiting for 30ms.
10-20 01:28:44.354: W/SoundPool(14307): Sample was not loaded. Waiting for 30ms.
10-20 01:28:44.384: W/SoundPool(14307): Sample was not loaded. Waiting for 30ms.
10-20 01:28:44.414: W/SoundPool(14307): Sample was not loaded. Waiting for 30ms.
10-20 01:28:44.444: W/SoundPool(14307): Sample was not loaded. Waiting for 30ms.
10-20 01:28:44.474: E/SoundPool(14307): sample 482 not READY
And the stacktrace
10-20 01:40:03.639: D/AndroidRuntime(22802): Shutting down VM
10-20 01:40:03.639: W/dalvikvm(22802): threadid=1: thread exiting with uncaught exception (group=0x40eb22a0)
10-20 01:40:03.664: E/AndroidRuntime(22802): FATAL EXCEPTION: main
10-20 01:40:03.664: E/AndroidRuntime(22802): android.content.res.Resources$NotFoundException: File res/drawable-ldpi/sam.mp3 from drawable resource ID #0x7f0203af
10-20 01:40:03.664: E/AndroidRuntime(22802): at android.content.res.Resources.openRawResourceFd(Resources.java:994)
10-20 01:40:03.664: E/AndroidRuntime(22802): at android.media.SoundPool.load(SoundPool.java:191)
10-20 01:40:03.664: E/AndroidRuntime(22802): at com.example.thai.PhraseActivity.loadSound(PhraseActivity.java:255)
10-20 01:40:03.664: E/AndroidRuntime(22802): at com.example.thai.PhraseActivity.access$3(PhraseActivity.java:252)
10-20 01:40:03.664: E/AndroidRuntime(22802): at com.example.thai.PhraseActivity$2.onChildClick(PhraseActivity.java:130)
10-20 01:40:03.664: E/AndroidRuntime(22802): at android.widget.ExpandableListView.handleItemClick(ExpandableListView.java:590)
10-20 01:40:03.664: E/AndroidRuntime(22802): at android.widget.ExpandableListView.performItemClick(ExpandableListView.java:522)
10-20 01:40:03.664: E/AndroidRuntime(22802): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3063)
10-20 01:40:03.664: E/AndroidRuntime(22802): at android.widget.AbsListView$1.run(AbsListView.java:3949)
10-20 01:40:03.664: E/AndroidRuntime(22802): at android.os.Handler.handleCallback(Handler.java:615)
10-20 01:40:03.664: E/AndroidRuntime(22802): at android.os.Handler.dispatchMessage(Handler.java:92)
10-20 01:40:03.664: E/AndroidRuntime(22802): at android.os.Looper.loop(Looper.java:137)
10-20 01:40:03.664: E/AndroidRuntime(22802): at android.app.ActivityThread.main(ActivityThread.java:4898)
10-20 01:40:03.664: E/AndroidRuntime(22802): at java.lang.reflect.Method.invokeNative(Native Method)
10-20 01:40:03.664: E/AndroidRuntime(22802): at java.lang.reflect.Method.invoke(Method.java:511)
10-20 01:40:03.664: E/AndroidRuntime(22802): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
10-20 01:40:03.664: E/AndroidRuntime(22802): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
10-20 01:40:03.664: E/AndroidRuntime(22802): at dalvik.system.NativeStart.main(Native Method)
10-20 01:40:03.664: E/AndroidRuntime(22802): Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
10-20 01:40:03.664: E/AndroidRuntime(22802): at android.content.res.AssetManager.openNonAssetFdNative(Native Method)
10-20 01:40:03.664: E/AndroidRuntime(22802): at android.content.res.AssetManager.openNonAssetFd(AssetManager.java:428)
10-20 01:40:03.664: E/AndroidRuntime(22802): at android.content.res.Resources.openRawResourceFd(Resources.java:991)
10-20 01:40:03.664: E/AndroidRuntime(22802): ... 17 more
And the source code:
weakExpandableList.get().setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
Object e = (Object)adapter.getChild(groupPosition, childPosition);
int nmbr_childs = adapter.getChildrenCount(groupPosition);
final int group_position = groupPosition;
// villkor för childitem.
switch (childPosition) {
case 0:
// tester huruvida ett eller två childitems. returvärdet fyller ingen funktion.
int x = (nmbr_childs > 1) ? loadAnimation_singleView(v, childPosition)
: loadAnimation_coupleView(v);
loadSound(0, group_position); // Här uppstår krasch ibland!
break;
case 1:
loadSound(1, group_position);
loadAnimation_singleView(v, childPosition);
break;
}
return true;
}
});
private void loadSound(int position, int group_position) {
switch (position) {
case 0:
myVoice = soundPool.load(PhraseActivity.wr.get(), sound[group_position][0], 2); // Här uppstår en crash ibland - resource not found exeption
soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId,
int status) {
soundPool.play(myVoice, 1, 1, 1, 0, 1.0f);
}
});
break;
case 1:
myVoice = soundPool.load(PhraseActivity.wr.get(), sound[group_position][1], 2);
soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId,
int status) {
soundPool.play(myVoice, 1, 1, 1, 0, 1.0f);
}
});
break;
}
}
Upvotes: 1
Views: 533
Reputation: 19280
My best guess is that you are not using SoundPool properly. Is this the same MP3 you are loading every time? It appears from the Soundpool javadoc, that SoundPool allows you to load audio resources from disk, and then play them as many times as you wish. If you are loading and playing the same clip, or several clips each time, then you are doing it wrong.
Upvotes: 1