In answering this question: I want to make a java program in which there is a combobox which displays the titles of all the files available in a folder
Another method of implementing the answer was brought to my attention; the usage of AudioSystem.getAudioFileTypes() to return all the supported audio files in the specified folder. I am a fairly inexperienced coder and am unable to integrate this method in my given answer
File someFolder = new File("pathname");
Object[] wavFiles = someFolder.listFiles(wavExtensionFilenameFilter);
JComboBox songComboBox = new JComboBox(wavFiles);
Can anyone show me how this would be done?
The following source will show a
JFileChooserthat is specific to file types understood by Java Sound. Once the user selects any sound clip, the app. will get a listing of all the clips in that directory and display them in a combo.On selecting a clip from the combo., we could play the sound in a
javax.sound.sample.Clip(or other ways using the Java Sound API), but instead we opt. for the 1.6+ ‘one-liner’ of usingDesktopto open the file (in the system default player).