Skip to content

Commit

Permalink
Fix folders having duplicate songs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeeses313 committed Nov 2, 2023
1 parent 4304257 commit fe2a1cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/musicplayer/MusicPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ public void changed(ObservableValue<? extends String> ov, String t, String t1) {
} else {
this.currentSong = this.list.getRandomSong("", this.currentFolder);
this.nextSong = this.list.getRandomSong(currentSong, this.currentFolder);
listView.getSelectionModel().select(currentSong);
listView.scrollTo(listView.getSelectionModel().getSelectedIndex());
}
currentSongLabel.setText("Playing now: " + currentSong);
nextSongLabel.setText("Playing next: " + nextSong);
Expand Down
8 changes: 3 additions & 5 deletions src/musicplayer/SongList.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.HashMap;
import java.util.Random;
import java.util.Stack;
import java.util.stream.Collectors;
import javafx.scene.media.Media;

public class SongList {
Expand Down Expand Up @@ -37,15 +38,12 @@ public boolean init(String path) {
this.initPart(musicFiles, folderStack);
Collections.sort(folderNames.subList(1, folderNames.size()));
for (String folderName : folderNames) {
this.folderContents.get(folderName).sort((name1, name2) -> name1.toLowerCase().compareTo(name2.toLowerCase()));
this.folderContents.put(folderName, new ArrayList<>(this.folderContents.get(folderName).stream().sorted((name1, name2) -> name1.toLowerCase().compareTo(name2.toLowerCase())).distinct().collect(Collectors.toList())));
}
} catch (Exception e) {

}
if (this.folderContents.get("All").isEmpty()) {
return false;
}
return true;
return !this.folderContents.get("All").isEmpty();
}

private void initPart(File[] musicFiles, Stack<String> folderStack) throws Exception {
Expand Down

0 comments on commit fe2a1cd

Please sign in to comment.