Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Media player play the song x times [closed]

I would like to play the song x times like 1,2,3 ..etc using android media player.Please let me know is there any way to do this using android api. Thanks

like image 537
sandeep1987 Avatar asked Jan 22 '13 11:01

sandeep1987


1 Answers

As Wamasa said, you could use setLooping for infinite playing. For playing only a specific count time, you can add an onCompletionListener to your MediaPlayer:

int count = 0; // initialise outside listener to prevent looping

mediaPlayer.setOnCompletionListener(new OnCompletionListener(){
  int maxCount = 3;

  @Override
  public void onCompletion(MediaPlayer mediaPlayer) {
    if(count < maxCount) {
      count++;
      mediaPlayer.seekTo(0);
      mediaPlayer.start();
    }
}});
like image 197
ConcurrentHashMap Avatar answered Sep 21 '22 01:09

ConcurrentHashMap