jeudi 28 décembre 2017

How to play next random song of the array of songs

I have an array of songs, My app play songs randomly when an activity is open but when the song is finished I would like to play another random song from the array, does anyone can help with it?

public MediaPlayer mediaPlayer;
private int songs[];


   songs = new int[] {
           R.raw.track1,
           R.raw.track2,
           R.raw.track3,
           R.raw.track4,
           R.raw.track5,
           R.raw.track6,
           R.raw.track7,
           R.raw.track8,
           R.raw.track9,
           R.raw.track10,
           R.raw.track11,
           R.raw.track12,
           R.raw.track13,
           R.raw.track14,
           R.raw.track15,
           R.raw.track16,
           R.raw.track17,
   };


    int randomSong =  new Random().nextInt(songs.length);
    mediaPlayer = MediaPlayer.create(this, songs[randomSong]);
    mediaPlayer.start();




Aucun commentaire:

Enregistrer un commentaire