I’m just starting android development and java, and this is my first app to get acquainted with android development. I’m almost done with the app, the only thing left is shuffling songs. I've been grappling with it for a couple of days now. I need urgent help, tried many steps to get it right, and I’ve scoured the web and SO for related question, yet, I still can’t get it right.
This snippet of code is in my Service class, Playlist is passed from Main Activity:
public void setPlayList(ArrayList<SongModel> playlist) {
playList = playlist;
//Arraylist of integer to hold the number of indices
list = new ArrayList<Integer>();
for(int i =0; i <= playList.size();i++){
list.add(i);
}
Collections.shuffle(list, new Random(System.nanoTime()));
}
The code below is how songs are played, this snippet is in configPlayBack() method that plays the song from the song id:
long item = 0;
item = playList.get(MusicPref.isShuffle(this)? list.get(position): position).getSongId();
the snippet for playing next song is:
public void playNext() {
position++;
if (position >= playList.size()) {
position = 0;
}
configPlayBack();
}
But the songs are still playing serially, Please i'ld really appreciate any help. been stuck here for too long. I'ld really appreciate a code/snippet answer.
Aucun commentaire:
Enregistrer un commentaire