如何连续播放raw文件夹里的歌曲,不循环播放

how to play song in raw folder continously, and no looping

我是新手,你能帮帮我吗??我想依次播放原始文件夹中的所有歌曲,所有歌曲播放完毕后我不想循环播放。

我试过这段代码,但它在播放所有歌曲后一直在循环 {

int [] sound;
int soundke = 0;
MediaPlayer mediaPlayer;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_kubus);

    sound = new int[] {R.raw.swoosh2, R.raw.swoosh1, R.raw.swoosh2};

    mediaPlayer = MediaPlayer.create(kubus.this, sound[0]);

    mediaPlayer.start();

    mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            play();

        }
    });

}

private void play () {
    soundke = (soundke + 1) % 3;
    AssetFileDescriptor afd = this.getResources().openRawResourceFd(sound[soundke]);

    try {
        mediaPlayer.reset();
        mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
        mediaPlayer.prepare();
        mediaPlayer.start();
        afd.close();
    } catch (IOException e) {

    }
}

歌曲播放完后还在循环。我不想在所有歌曲播放后循环播放,感谢您的帮助

  int [] sound;
    int soundke = 0;
    MediaPlayer mediaPlayer;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kubus);

        sound = new int[] {R.raw.swoosh2, R.raw.swoosh1, R.raw.swoosh2};

        mediaPlayer = MediaPlayer.create(kubus.this, sound[0]);
        mediaPlayer.setLooping(false);
        mediaPlayer.start();

        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                if(soundke < sound.length-1){
                   play(++soundke);
                }else{
                    soundke=0; 
                    mediaPlayer.stop();    
}
            }
        });

    }

    private void play (int track) {
        //soundke = (soundke + 1) % 3;
        AssetFileDescriptor afd = this.getResources().openRawResourceFd(sound[track]);

        try {
            mediaPlayer.reset();
            mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
            mediaPlayer.setLooping(false);
            mediaPlayer.prepare();
            mediaPlayer.start();
            afd.close();
        } catch (IOException e) {

        }
    }