我试图在第一首歌完成后自动播放歌曲,问题是我不知道如何判断第一首歌的结束时间。代码在下面,我试图在mediaPlayer完成播放后播放mediaPlayer2。 MediaPlayer mediaPlayer,mediaPlayer2;
public class MainActivity extends AppCompatActivity {
// global variable
MediaPlayer mediaPlayer, mediaPlayer2;
public void play(View view)
{
// play music if you want this to start from the beginning put this in oncreate method
mediaPlayer.start();
// set loop
mediaPlayer.setLooping(true);
}
public void pause(View view)
{
// pause music
mediaPlayer.pause();
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// create media player variable and link it to the music you want
mediaPlayer = MediaPlayer.create(this, R.raw.a);
mediaPlayer2 = MediaPlayer.create(this, R.raw.b);
}
}
答案 0 :(得分:1)
mediaPlayer.setOnCompletionListner(New OnCompletionListener {
@Override
public void onCompletion(MediaPlayer mp) {
//addyourcodehere
}
)};
答案 1 :(得分:1)
设置OnCompletionListener可以帮助您 https://developer.android.com/reference/android/media/MediaPlayer.OnCompletionListener.html
#include "List.h"
template <typename T>
const T& List<T>::const_iterator::operator*() const
{
//do stuff
}