简体   繁体   中英

Playlists for mp3 files in Java using BufferedReader & BufferedWriter

I've been working on a really simple mp3 player in java for some weeks now and I'm wondering if I can do playlist with a BufferedReader and BufferedWriter method. For example with JFileChooser I'd choose song and store its path to file (for example "playlist.txt") and then in while loop ( BufferedReader.available() ) I'd read path and play it. Is this possible? Or Is it better to set chooser.setMultiSelectionEnabled() to true and work in this direction?

Seems like the best solution for this would be making a BufferedReader over the FileReader to read the file. Then you can make java.io.File objects and put those into a java.util.ArrayList . Then you can get the files easily from from the ArrayList and dispose the readers. You can also add an refresh method to refresh the list if needed.

What I did was use a for loop like this:

File playlist = new File("U:\\186Project\\Project\\data");
for(File f : playlist.listFiles()){
  song = minim.loadFile(f.getName(), 2048);
  ......
}

I was using Processing to make LEDs light up to the beat of music, if you want to check out the full code out go here .

This won't let you choose certain songs but it does cycle through them like a playlist. Make sure to change "U:\\186Project\\Project\\data" to whatever directory has all your MP3 files in it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM