本文介绍了如何在活动的后台打了很多的声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我要玩3首歌曲。当第1歌曲结束,第2曲开始,并且当第二首歌曲结束时,第3次曲开始,并且当第3次歌曲结束,第1曲再等等开始。在这里使用 mp.setOnCompletionListener
For example, I want to play 3 songs. When the 1st song ends, the 2nd song begins, and when the 2nd song ends, the 3rd song begins, and when the 3rd song ends, the 1st song begins again and so on. Is the mp.setOnCompletionListener
used here?
推荐答案
您是对的。你可以做这样简单的东西:
You are right. You can do something simple like this:
public class MainActivity extends Activity {
MediaPlayer mp1, mp2, mp3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mp1 = MediaPlayer.create(this, R.raw.music_1);
mp2 = MediaPlayer.create(this, R.raw.music_2);
mp3 = MediaPlayer.create(this, R.raw.music_3);
mp1.start();
mp1.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp2.start();
}
});
mp2.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp3.start();
}
});
mp3.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp1.start();
}
});
}
}
这将播放MP1和它onCompletion,它将发挥MP2,和MP2的onCompletion,它会播放MP3,以及MP3的onCompletion,它会再次发挥MP1等等...
This will play mp1 and onCompletion of it, it will play mp2, and onCompletion of mp2, it will play mp3, and onCompletion of mp3, it will play mp1 again and so on...
这篇关于如何在活动的后台打了很多的声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!