Two audio songs is played simultaneously in an android, how we fix it?

Viewed 27

I work on music player app, which read audio songs from device storage and display in recyclerview. When i click on any song it play in an other activity and when we press back button song is still playing but when i want to play another song and click on another song it also opens PlayerActivity.java but there in(PlayerActivity.java) previouse and new song both are playing simultaneously. How we fix it that when we click on next song current song should be finish? Here is my code :

1 Answers

First, you need to stop that song and for that, you can use the reset method of "MediaPlayer" and then start that new song.

MediaPlayer mp = new MediaPlayer();
mp.reset();
mp.prepare();
mp.start();
Related