mediaplayer通过- mediaPlayer.setLooping(true);
可以设置循环播放。但是,有时候我们需要设置具体的播放次数,而不是一直循环播放,比如读单词的时候,想要读两次,这个是loop就不行了。解决办法是在播放完成事件中处理,通过设置播放的次数,在完成事件中再次调用播放,直到次数够了为止。
- mediaPlayer.setOnCompletionListener(
- new MediaPlayer.OnCompletionListener()
- {
- @Override
- public void onCompletion(MediaPlayer arg0)
- {
- try
- {
- if(0==soundCount)
- {
- mediaPlayer.start();
- soundCount++;
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- });
上面是设置播放两次。在其他地方吧soundCount置零即可。
|