1
   class One {

    public static void main(String[] arg) {
        new One().play();
    }

    public void play() {
        try {
            AudioClip clip = Applet.newAudioClip(new URL(
                    "file:\\C:\\Documents and Settings\\admin\\Desktop\\javabottle-open.wav"));
            clip.play();
            URL ur = new URL("file:\\C:\\Documents and Settings\\admin\\Desktop\\flute+hrn+mrmba.aif");
            clip = Applet.newAudioClip(ur);
            clip.play();
            Thread.sleep(10000);
        } catch(Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

例外メッセージが表示されず、オーディオも再生されません。

4

1 に答える 1

1

これは私のために働く

public class ClipTest {

    public void run() throws UnsupportedAudioFileException, IOException, LineUnavailableException {
        InputStream inRequest = this.getClass().getResourceAsStream("batR.wav");
        AudioInputStream sound = AudioSystem.getAudioInputStream(inRequest);

        DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());
        Clip clip = (Clip) AudioSystem.getLine(info);
        clip.open(sound);

        clip.addLineListener(new LineListener() {

            public void update(LineEvent event) {
                if(event.getType() == LineEvent.Type.STOP) {
                    event.getLine().close();
                    System.exit(0);
                }
            }
        });

        clip.start();

    }

    public static void main(String[] args) throws Exception {
        ClipTest clipTest = new ClipTest();
        clipTest.run();

    }
}
于 2013-02-19T09:21:55.370 に答える