I want to play a sound in an Android app by clicking a Button. But in the emulator the app quites immediately after starting.
public class FullscreenActivity extends Activity {
private MediaPlayer mediaPlayer = MediaPlayer.create(this.getApplicationContext(), R.raw.sound_file_1);
......
public void playsound(View view){
mediaPlayer.setLooping(true);
if(mediaPlayer.isPlaying() ){
mediaPlayer.pause();
}
else{
mediaPlayer.start();
}
}
This is the function which is called by this button in the layout-xml:
<Button android:id="@+id/dummy_button"
style="?buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick = "playsound"
android:text="@string/dummy_button" />
I'm worring the file could not be found, but i don't know why. It is in the folder "projectname/src/main/res/raw/sound_file_1" First, the file had the ending ".mp3", but i deleted it as I thought this could help.
In the device logcat, there is an error message, which says:
09-21 00:00:58.044 2075-2075/com.example.projectname E/Trace﹕ error opening trace file: No such file or directory (2)
thank you for your help!