如何设置两次或三次响铃声?

时间:2017-10-25 05:37:08

标签: android

我设置了定制的叮咚铃声,但它响了一次。如何设置两次或三次响铃声。

这里是java Code,

 mMediaPlayer = new MediaPlayer();
                mMediaPlayer = 
 MediaPlayer.create(MyRideDetailTrackRide.this, R.raw.dingdong);
                mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
              // mMediaPlayer.setLooping(true);
                mMediaPlayer.start();

1 个答案:

答案 0 :(得分:2)

int howManyTimesPlayed = 0;
mediaPlayer.setOnCompletionListener(new OnCompletionListener(){
int maxRePlayCount = 3; // set this value to replay x time

@Override
public void onCompletion(MediaPlayer mediaPlayer) {
    if(howManyTimesPlayed < maxRePlayCount) {
      howManyTimesPlayed++;
      mediaPlayer.seekTo(0);
      mediaPlayer.start();
    }
}});