Play / stop button - how to make music play back from the beginning? Stop function not pause function ``
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
b_play = (Button) findViewById(R.id.b_play);
b_play.setEnabled(false);
b_play.setText("Loading");
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
new PlayerTask().execute(stream);
b_play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view ) {
if (started) {
started = false;
mediaPlayer.pause();
b_play.setText("PLAY");
} else {
started = true;
mediaPlayer.start();
b_play.setText("STOP");
}
}
});
Thank you for your help
Call mediaPlayer.seekTo(0)
after mediaPlayer.pause();
b_play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view ) {
if (started) {
started = false;
mediaPlayer.pause();
mediaPlayer.seekTo(0);
b_play.setText("PLAY");
} else {
started = true;
mediaPlayer.start();
b_play.setText("STOP");
}
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.