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());
        }
    }
}

I am not getting any exception message & the audio is also not being played.

Festus Tamakloe
  • 11,231
  • 9
  • 53
  • 65
sunya
  • 43
  • 4
  • possible duplicate of [How to play .wav files with java](http://stackoverflow.com/questions/2416935/how-to-play-wav-files-with-java) – McDowell Feb 19 '13 at 09:11
  • 1
    You will make your life easier if you use / in path names. – Ingo Feb 19 '13 at 09:12
  • @Ingo OP, and you will make your life even more easier if you all use [File.separator](http://docs.oracle.com/javase/1.4.2/docs/api/java/io/File.html#separator) in path names. – ppeterka Feb 19 '13 at 09:16
  • should not have any spaces in the folder names. for example "Documents and Settings" – codeMan Feb 19 '13 at 09:20

1 Answers1

1

This works for me

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();

    }
}
Festus Tamakloe
  • 11,231
  • 9
  • 53
  • 65