Search code examples
androidlistviewandroid-mediaplayer

Media Player On Complete Clicks 2nd Button from Listview


I have a list of Songs and in UI, there are three Buttons named as play ,pause and resume. Now on MediaPlayer.OnCompletionListener(), i want to performclick() on second Button of list view so that it could automatically play next song.

mPlayerforplanet.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
              viewHolder.play_button.getTag(position);
                    viewHolder.play_button.performClick();
                }
            }
        });

This piece of code works well in android emulator but not in mobile device. if i am playing the first song, after completion of first song it going to 4th song and next 7th. Please help!! Thank you.


Solution

  • When a user first clicks the list set an integer to that list item position.On completion increment the integer and get the song data from listview adapter and play that song.Change the status of your play button according to the integer in adapter class.