如何在完成一首歌后播放下一首歌?

时间:2017-09-09 22:40:39

标签: java android android-mediaplayer

我正在尝试创建一个媒体播放器。为此,我试图在完成前一首歌后播放下一首歌。这是我的代码:

<html>
<head>
  <title>Products and Sizes</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>

 <select name="adidas">
  <option value="">Select Adidas Products</option>
  <option value="shoes">Shoes</option>
  <option value="pants">Pants</option>
  <option value="shirts">Shirts</option>
</select>
<select data-related="adidas"></select>

<select name="nike">
  <option value="">Select Nike Products</option>
  <option value="hats">Hats</option>
  <option value="jackets">Jackets</option>
  <option value="shirts">Shirts</option>
</select>

<select data-related="nike"></select>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您要找的是setOnCompletionListener。这允许您在播放完成后从MediaPlayer获得回调。您可以在那里开始下一首曲目:

mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
    void onCompletion(MediaPlayer mp){
        //play next track
        play(mNextTrack);
    }
})

有关详细信息,请参阅Android documentation