Reputation: 31
How to stop previous playing song before playing next song and i get the after alter my code,this is my altered code
public void pl(int songindex)
{
if(mp.isPlaying())
{
mp.stop();
if(songindex==0)
{
mp=MediaPlayer.create(this, R.raw.gayatri);
mp.start();
}
else if(songindex==1)
{
mp=MediaPlayer.create(this, R.raw.brahma);
mp.start();
}
}
}
Upvotes: 3
Views: 123
Reputation: 2799
When you click the "next song" button run this code first
if(mp.isPlaying())
{
mp.stop();
//rest of your code
}
Upvotes: 4
Reputation: 87
public void pl(int songindex)
{
if(mp!=null)
{
mp.stop()
........
........\\your code here
}
else if(mp==null)
{
......
......\\your code here
}
}
Upvotes: 3