SamplePlayer { public void play(File file) { try { AudioInputStream stream; AudioFormat format; DataLine.Info info; final Clip clip; stream = AudioSystem.getAudioInputStream(file); format = stream.getFormat(); info = new DataLine.Info(Clip.class, format); clip = (Clip) AudioSystem.getLine(info); clip.addLineListener(new LineListener() { public void update(LineEvent event) { if (event.getType() == LineEvent.Type.STOP) clip.close(); } }); clip.open(stream); clip.start(); } catch (Exception e) { throw new RuntimeException(e.getClass().getSimpleName() + " " + e.getMessage()); } }  void play(File file);  }
@Test public void testPlay() throws Exception { final File file = new File("build.wav"); new SamplePlayer().play(file); }