Reputation: 19
I have a listview. When i pressed my first music, it is playing. When i pressed same music again, i have an error. I want that i can play and pause as i want. First press is play, second press is stop, thirth press is again play
Here is code
public void onItemClick(AdapterView<?> arg0, View arg1, int position,long id)
{
switch(position)
{
case 0 :
if(sound.isPlaying())
{
sound.stop();
sound.release();
}
if(!sound.isPlaying())
{
sound.start();
}
break;
Upvotes: 1
Views: 174
Reputation: 631
try to initiate player before play
public void onItemClick(AdapterView<?> arg0, View arg1, int position,long id)
{
switch(position)
{
case 0 :
if(sound.isPlaying())
{
sound.stop();
sound.release();
}
if(!sound.isPlaying())
{
sound = new MediaPlayer();
sound.setDataSource(filename);
sound.prepare();
sound.start();
}
Upvotes: 1