本文介绍了Android Media Player播放歌曲x次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用android媒体播放器播放1,2,3 ..etc等歌曲x次.请让我知道有没有使用android api做到这一点的方法.谢谢
I would like to play the song x times like 1,2,3 ..etc using android media player.Pleaselet me know is there any way to do this using android api.Thanks
推荐答案
正如Wamasa所说,您可以使用setLooping进行无限播放.要仅播放特定的计数时间,可以将onCompletionListener添加到MediaPlayer:
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();
}
}});
这篇关于Android Media Player播放歌曲x次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!