SongHandler.java 932 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package model;
  2. import java.io.File;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import main.Window;
  6. import audio.Song;
  7. import audio.io.DirScanner;
  8. public class SongHandler {
  9. private List<Song> songs;
  10. private Song currentSong;
  11. private int currentIndex;
  12. private File dir;
  13. public SongHandler()
  14. {
  15. songs = new ArrayList<Song>();
  16. currentSong = null;
  17. currentIndex = 0;
  18. if(Window.ON_RASP)
  19. dir = new File(System.getProperty( "user.home" ) + "/ColorStrike/Songs");
  20. else
  21. dir = new File("Songs");
  22. songs = DirScanner.scanDirectories(dir);
  23. currentSong = songs.get(currentIndex);
  24. for(Song s : songs)
  25. {
  26. System.out.println(s.getTitle());
  27. }
  28. }
  29. public void next()
  30. {
  31. currentIndex++;
  32. currentIndex%=songs.size();
  33. currentSong = songs.get(currentIndex);
  34. }
  35. public void previous()
  36. {
  37. currentIndex--;
  38. currentIndex%=songs.size();
  39. currentSong = songs.get(currentIndex);
  40. }
  41. }