Good morning. I'm doing a simple test where I press a button and a sound plays. When emulating the application (or using it in the mobile) and clicking the button, the app is peta and closes. I think the problem is that it does not find the audio file, because I have another method in which I play a sound that I record and it does not give me any problem, since that audio is created by the app itself and I know where it is. The code is this:
Definition of the button in XML
public void soundTest (View view) {
mediaPlayer = new MediaPlayer();
mediaPlayer.create(this, R.raw.test);
try {
mediaPlayer.prepare();
mediaPlayer.start();
} catch (IOException e) {
Log.e(LOG_TAG, "Fallo en reproducción");
}
}
The function that the button calls
<Button
android:id="@+id/sound"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sound"
android:onClick="soundTest"/>
I have created the folder "raw" and the file "test.mp3" is in it. Do not throw me any errors