I am a beginner in Android Studio, and I made a button which plays and stops a sound (labeled start/stop) but after the sound play is complete, the button doesn't show the start
text again.
How can I make the button change its text to start when playback is done?
How can I make the sound stop when switching to another view?
my code:
public class insideaventador extends Activity {
MediaPlayer mysound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.insideaventador);
mysound = MediaPlayer.create(this, R.raw.lamborghini);
}
public void startup(View v) {
Button button = (Button) v;
if (mysound == null) {
mysound = MediaPlayer.create(insideaventador.this, R.raw.lamborghini);
}
if (mysound.isPlaying()) {
mysound.pause();
((Button) v).setText("START");
} else {
mysound.start();
((Button) v).setText("STOP");
}
}
}