Katherine99
Katherine99

Reputation: 990

Android: MP3 not stopping when the activity ends

I have a group a mp3 into an array and my app plays them properly. However when the user quits that activity the activity stops but the mp3s keep being played.

Here is the code: Initially I play the mp3 files in an array:

 MediaPlayer mPlay = MediaPlayer.create(this, Audios[posicion]);
         mPlay.start();

When the user clicks on a certain button the activity ends but the MediaPlayer doesnt stop:

    bFinalizar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPlay.stop();
                posicion=0;
                Listening2.this.finish();
            }
        });

Upvotes: 0

Views: 85

Answers (2)

Göksel Güren
Göksel Güren

Reputation: 1479

Try this snippet

try {

mPlayer.stop();

mPlayer.release();

} catch(Exception ex) {

 ex.printStackTrace()    

}

Upvotes: 1

Mus
Mus

Reputation: 1860

Try calling mPlay.stop() in onFinish() or onDestroy() of your activity.

Upvotes: 0

Related Questions