Hi guys,
I am new to android and I want to make a simple app for learning purposes.
So the app should be like this: if I press Button1, it will sing the sound1. If I press Button 2 the sound1 stops and plays sound2.
Here is what I made so far, but it doesn't work. I tried to search on different websites, but I didn't find anything that could help me so I thought it would be helpful a forum.
Any help please?
Thank you!
I am new to android and I want to make a simple app for learning purposes.
So the app should be like this: if I press Button1, it will sing the sound1. If I press Button 2 the sound1 stops and plays sound2.
Here is what I made so far, but it doesn't work. I tried to search on different websites, but I didn't find anything that could help me so I thought it would be helpful a forum.
Any help please?

Thank you!
Java:
package com.example.moan;
import androidx.appcompat.app.AppCompatActivity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
MediaPlayer cricket;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnCricket = (Button) this.findViewById(R.id.button);
btnCricket.setOnClickListener(this);
Button btnCricket2 = (Button) this.findViewById(R.id.button2);
btnCricket2.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.button:
closeCricket();
cricket = MediaPlayer.create(this, R.raw.manea1);
break;
case R.id.button2:
closeCricket();
cricket = MediaPlayer.create(this, R.raw.manea2);
break;
default:
return;
}
cricket.start();
}
public void closeCricket() {
if (cricket.isPlaying()) {
cricket.pause();
cricket.reset();
cricket.release();
} else {
cricket.reset();
cricket.release();
}
}
}