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.

4
  • possible duplicate of How to play .wav files with java Commented Feb 19, 2013 at 9:11
  • 1
    You will make your life easier if you use / in path names. Commented Feb 19, 2013 at 9:12
  • @Ingo OP, and you will make your life even more easier if you all use File.separator in path names. Commented Feb 19, 2013 at 9:16
  • should not have any spaces in the folder names. for example "Documents and Settings" Commented Feb 19, 2013 at 9:20

1 Answer 1

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(); } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.