All pastes #996028 Raw Edit

roundyz

public java v1 · immutable
#996028 ·published 2008-04-24 17:48 UTC
rendered paste body
	/**		 * add some sound		 */		File buttonClickedSoundFile = new File("click.wav");		// check file path		System.out.println(buttonClickedSoundFile.getAbsolutePath());		AudioInputStream ais;		try {			ais = AudioSystem.getAudioInputStream(buttonClickedSoundFile);			AudioFormat af = ais.getFormat();			System.out.println("Sample rate is: " + af.getSampleSizeInBits() + "bps");			SourceDataLine sdl = null;			try {				sdl = AudioSystem.getSourceDataLine(af);				// check to see if the line is open				if (sdl.isOpen()) {					System.out.println("line open");				} else {					System.out.println("line closed, trying to open");					sdl.open(af);				}				System.out.println("Line open: " + sdl.isOpen());				// Check the volume				System.out.println("Volume at:" + sdl.getLevel());				sdl.start();				// Check the dataline				System.out.println("Dataline running: " + sdl.isRunning());				System.out.println("Buffer size in bytes: " + sdl.getBufferSize());			} catch (LineUnavailableException e1) {				System.out.println("Sorry Line is busy");			} finally {				sdl.drain();				sdl.close();			}		} catch (UnsupportedAudioFileException e) {			System.out.println("Sorry, unsupported File type.");		} catch (IOException e) {			System.out.println("Sorry there is an IO error, check file permissions.");		}