I want to make a simple music player. So I filtered the .mp3
files from the PC directory and showed them in JList
. But when I select the song from JList
, the song is not playing and showing error
like this
java.io.FileNotFoundException: F:\Java in Eclipse\NewMusicPlayer\(song name).mp3 (The system cannot find the file specified)
My Code is given below
Code of File Filtering :
MP3Player mp3;
private void setMusic() {
File home = new File("E:\\MUSICS COLLECTION");
Collection<File> mp3Files = FileUtils.listFiles(home, new String[] { "mp3" }, true);
@SuppressWarnings("rawtypes")
DefaultListModel showData = new DefaultListModel();
for (File file : mp3Files) {
showData.addElement(file.getName());
mp3 = new MP3Player(new File(file.getName()));
}
musicList.setModel(showData);
}
Code of JList
Selected Item :
musicList = new JList();
musicList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent arg0) {
mp3.play();
}
});