Returning a list of audio filetypes

前端 未结 1 1664
甜味超标
甜味超标 2021-01-25 21:59

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

1条回答
  •  清酒与你
    2021-01-25 22:19

    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.

    Sound clip list

    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 using Desktop to open the file (in the system default player).

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.filechooser.FileNameExtensionFilter;
    import javax.sound.sampled.*;
    import java.io.*;
    
    class GetSoundsByFileType {
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    AudioFileFormat.Type[] formatTypes = AudioSystem.getAudioFileTypes();
                    String[] types = new String[formatTypes.length];
                    for(int ii=0; ii

    0 讨论(0)
提交回复
热议问题