简体   繁体   English

使用BufferedReader和BufferedWriter的Java中mp3文件的播放列表

[英]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. 我已经使用Java在一个非常简单的mp3播放器上工作了几周,我想知道是否可以使用BufferedReaderBufferedWriter方法来制作播放列表。 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. 例如,使用JFileChooser我选择歌曲并将其路径存储到文件中(例如“ playlist.txt”),然后在while循环中( BufferedReader.available() )读取路径并播放。 Is this possible? 这可能吗? Or Is it better to set chooser.setMultiSelectionEnabled() to true and work in this direction? 还是将chooser.setMultiSelectionEnabled()设置为true并朝这个方向工作会更好?

Seems like the best solution for this would be making a BufferedReader over the FileReader to read the file. 似乎最好的解决方案是在FileReader上创建一个BufferedReader以读取文件。 Then you can make java.io.File objects and put those into a java.util.ArrayList . 然后,可以制作java.io.File对象,并将其放入java.util.ArrayList Then you can get the files easily from from the ArrayList and dispose the readers. 然后,您可以轻松地从ArrayList获取文件并配置阅读器。 You can also add an refresh method to refresh the list if needed. 如果需要,您还可以添加刷新方法来刷新列表。

What I did was use a for loop like this: 我所做的是使用这样的for循环:

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 . 我用处理,使LED指示灯亮起,音乐的节奏,如果你想看看完整的代码出去这里

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. 确保将“ U:\\ 186Project \\ Project \\ data”更改为包含所有MP3文件的目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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