返回音频文件类型列表
在回答这个问题时: 我想制作一个java程序,其中有一个组合框,显示文件夹中所有可用文件的标题
另一种实现答案的方法引起了我的注意;使用 AudioSystem.getAudioFileTypes() 返回指定文件夹中所有支持的音频文件。我是一个相当缺乏经验的编码员,无法将此方法集成到我给定的答案中
File someFolder = new File("pathname");
Object[] wavFiles = someFolder.listFiles(wavExtensionFilenameFilter);
JComboBox songComboBox = new JComboBox(wavFiles);
有人可以告诉我这是如何完成的吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下源代码将显示特定于 Java Sound 理解的文件类型的
JFileChooser
。一旦用户选择任何声音剪辑,应用程序就会启动。将获取该目录中所有剪辑的列表并以组合形式显示它们。从组合中选择剪辑时,我们可以在
javax.sound.sample.Clip
中播放声音(或使用 Java Sound API 的其他方式),但我们选择这样做。对于 1.6+ 使用Desktop
打开文件的“一行”(在系统默认播放器中)。The following source will show a
JFileChooser
that 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 usingDesktop
to open the file (in the system default player).