I'm new to java and i'm struggling with this for a long time. I'm making a soundboard and whenever a cardview is pressed i want it to play a sound and change the background color of the cardview for the duration of the audio. How can i make this happen? Playing the sound and changing the color are already working but i don't know how to set a duration or something. Can anyone help me out?
final MediaPlayer bingoMediaPlayer = MediaPlayer.create(this, R.raw.bingo);
final CardView bingo = (CardView) this.findViewById(R.id.play_bingo);
bingo.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
bingoMediaPlayer.start();
bingo.setCardBackgroundColor(Color.parseColor("#FF6F00"));
Toast.makeText(MainActivity.this,"kekkkk", Toast.LENGTH_SHORT).show();
}
});
Reset the color when the audio is completed. For this you could use the OnCompletionListener.
bingoMedia.setOnCompletionListener {
bingo.setCardBackgroundColor(Color.parseColor("your_default_color"))
}
You can find the original documentation here: MediaPlayer.OnCompletionListener