user2604411
user2604411

Reputation: 11

How can I do the "Stop" button in Android?

I'm creating an app for android using mediaplayer. I just created the "play", and the pause button. Here is my code:

player = MediaPlayer.create(this, R.raw.iinfancia);

try {
    player.prepare();
}
catch (Exception e) {
}

play.setOnClickListener(new View.OnClickListener() {
    public void onClick(View arg0) {
        player.start();
    }
});

pausar.setOnClickListener(new View.OnClickListener() {   
    public void onClick(View arg0) { 
        player.pause();
    } 
});

Now I want to know, how do I make the "stop" button, because when I do this:

stop.setOnClickListener(new View.OnClickListener() {
    public void onClick(View arg0) { 
        player.stop();
    }
});

The song stop, but when I click at "Play" again, the sound doesn't start.

Upvotes: 0

Views: 189

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93542

Use player.pause() instead. Just like a cd player, stop ends playback permanently, pause lets you restart from that point.

Upvotes: 2

Related Questions