if (addMode == AddMode.REPLACE) {
clearPlaylist();
}
int insertIdx = (addMode == AddMode.LAST ? playlist.size() : currentSongIndex + 1);
for (int i = 0; i < songs.size(); i++) {
Song song = songs.get(i);
log.info("adding: " + song);
if (insertIdx <= playlist.size()) {
playlist.add(insertIdx, song);
} else {
insertIdx = playlist.indexOf(song);
}
if (i == 0 && (addMode == AddMode.NOW || addMode == AddMode.REPLACE)) {
currentSongIndex = insertIdx;
}
insertIdx++;
}
if (addMode == AddMode.NOW || addMode == AddMode.REPLACE) {
Song song = songs.get(0);
stopPlaying();
startPlaying(song, 0, 0);
}
}