import java.io.*;import javax.sound.sampled.*;public class Sounds { static AudioInputStream ais; static Clip clip; public static void playSampleFile(String name, float pan, float gain) throws Exception { // AudioInputStream öffnen System.out.println("Start"); try{ ais = AudioSystem.getAudioInputStream(new File(name)); System.out.println("1A"); } catch (IOException e){ System.out.println("IOException!"); System.out.println("1B"); } catch (UnsupportedAudioFileException e){ System.out.println("UnsupportedAudioFileException!"); System.out.println("1C"); } AudioFormat format = ais.getFormat(); //ALAW/ULAW samples in PCM konvertieren if ((format.getEncoding() == AudioFormat.Encoding.ULAW) || (format.getEncoding() == AudioFormat.Encoding.ALAW)){ AudioFormat tmp = new AudioFormat( AudioFormat.Encoding.PCM_SIGNED, format.getSampleRate(), format.getSampleSizeInBits() * 2, format.getChannels(), format.getFrameSize() * 2, format.getFrameRate(), true ); ais = AudioSystem.getAudioInputStream(tmp, ais); format = tmp; } // Clip erzeugen und öffnen DataLine.Info info = new DataLine.Info( Clip.class,format,((int) ais.getFrameLength() * format.getFrameSize())); try{ clip = (Clip)AudioSystem.getLine(info); clip.open(ais); System.out.println("2A"); } catch (IOException e){ System.out.println("IOException!"); System.out.println("2B"); } catch (LineUnavailableException e){ System.out.println("LineUnavailableException!"); System.out.println("2C"); } // PAN einstellen FloatControl panControl = (FloatControl)clip.getControl(FloatControl.Type.PAN); panControl.setValue(pan); //MASTER_GAIN einstellen FloatControl gainControl = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(gain); //Clip abspielen System.out.println("vor start"); System.out.println("Framelength: "+clip.getFrameLength()); System.out.println("Frameposition: "+clip.getFramePosition()); System.out.println("Format: "+clip.getFormat()); System.out.println("Active: "+clip.isActive()); System.out.println("Open: "+clip.isOpen()); System.out.println("Level: "+clip.getLevel()); clip.start(); while(true) { try { Thread.sleep(100); }catch(Exception e) { //nothing } if(!clip.isRunning()) { break; } } clip.stop(); System.out.println("nach start"); clip.close(); } public static void main(String[] args){ try{ playSampleFile("c:/move.wav",Float.parseFloat("5"),Float.parseFloat("5")); } catch(Exception e){ e.printStackTrace(); System.exit(1); } System.exit(0); }}