Still haven't found an answer to this question. I've been copying and pasting source code from a book, and this is one of the example activities. Unfortunately when I run the activity it goes straight to the "catch" meaning that the "try" failed. When debugging, it seems like I get a FileNotFound exception at "AssetFileDescriptor descriptor = assetManager.openFd("bloop.wav")". I put the file in the project's assets folder just like I do with any other file (right click assets>new>file>select file to upload). I see the file in the eclipse hierarchy inside assets as I should. Is there something else I'm not doing? do I need to declare the asset in the manifest file or something? Any help is greatly appreciated. thanks
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
setContentView(textView);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaPlayer = new MediaPlayer();
try {
AssetManager assetManager = getAssets();
AssetFileDescriptor descriptor = assetManager.openFd("bloop.wav");//This is the exception
mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(),descriptor.getLength());
mediaPlayer.prepare();
mediaPlayer.setLooping(true);
} catch (IOException e) {
Log.d("TAG", "Error was this ", e);
mediaPlayer = null;
}
}
And here is my error, for those of you that will want the full logcat:
Error was this
java.io.FileNotFoundException: bloop.wav
at android.content.res.AssetManager.openAssetFd(Native Method)
at android.content.res.AssetManager.openFd(AssetManager.java:332)
at com.example.secondproject.MediaPlayerTest.onCreate(MediaPlayerTest.java:24)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)