I'm really new at java and android and I'm trying to play some sound after a button is pressed. I searched a lot and tried this:
//package and imports
public class Simulador extends Activity {
int contador;
Button somar;
SoundPool som;
boolean loaded;
int comeu, comprou;
protected void onCreate(Bundle primeiroBundle) {
super.onCreate(primeiroBundle);
setContentView(R.layout.activity_primeira_atividade);
contador = 0;
somar = (Button) findViewById(R.id.som);
som = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
//I removed the whole part from the other button,
//since it's basically the same. So that's why I need to set maxStreams to 2.
comeu = som.load(this, R.raw.comeu, 1);
som.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
public void onLoadComplete(SoundPool som, int sampleId, int status){
loaded = true;
}
});
somar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (loaded) {
som.play(comprou, 1, 1, 1, 0, 1f);
}
contador += 5;
}
}
});
}
protected void onPause() {
super.onPause();
som.release();
som = null;
}
}
My code is working as it should, but I got the follwing warning:
SoundPool(int, int, int)' is deprecated
So I came here to see how to solve and got this:
This constructor was deprecated in API level 21. use SoundPool.Builder instead to create and configure a SoundPool instance
So I went here but couldn't addapt my code to this new constructor, even reading the reference. Does anyone know how to solve this?