I apologize for my noobiness in java, but I am trying to make a very basic app for someone for their birthday and have only really done any programming in python. I have been trying to implement the code found in android - how to make a button click play a sound file every time it been pressed? and am having trouble. I have placed the assets folder in the main directory, the src directory, and the app directory to see if any helped and am still getting the error
Every time I attempt to run the program I get the following error
02-27 23:06:48.896 25643-25643/com.app.bdking.mineturtle W/System.err﹕ java.io.FileNotFoundException: hello.mp3
Here is my main activity
package com.app.bdking.mineturtle;
import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import java.io.IOException;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final MediaPlayer mp = new MediaPlayer();
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mp.isPlaying())
{
mp.stop();
}
try {
mp.reset();
AssetFileDescriptor afd;
afd = getAssets().openFd("hello.mp3");
mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
mp.prepare();
mp.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
main xml is the same as on the aforementioned post.
Thanks in advance.