媒体播放器播放 2 首歌曲

Mediaplayer play 2 songs

无法切换歌曲

对这件事完全陌生。

I have two buttons in my android app.

I'd like to play 2 songs using MediaPlayer.

When I play one button, everything is fine, but when I start the 2nd button, the first song is still playing. How do I stop that?

您需要结束第一首歌曲,然后开始第二首歌曲。所以对于每个按钮,做这样的事情。您需要先检查音乐是否正在播放,如果是,则结束音乐。然后开始你的新歌

    if (mPlayer.isPlaying()) {
        mPlayer.stop();
        mPlayer.reset();
        mPlayer.release();    
    }

   mPlayer = MediaPlayer.create(this, Song1); //then song2 
   mPlayer.start();