Date: Thu, 16 Jan 2003 17:55:36 +0800 From: Suken Woo <wsk@mail.gddsn.org.cn> To: java@freebsd.org Subject: jdk1.3.1 bug? Message-ID: <3E268198.2010401@mail.gddsn.org.cn>
next in thread | raw e-mail | index | archive | help
hi,hacks: when running the following java prog, jdk1.3.1's EventListener seams just listened the reverse responsed event.if u move the mouse and press any keys , the program will play sounds normally,until u stopped the mouse or keyboad input event.but things would not occur under jdk1.4. in faintting --the src import java.net.URL; import java.net.MalformedURLException; import java.util.Date; import javax.sound.sampled.*; import javax.swing.JOptionPane; import cn.gd.seismology.rts.event.*; class RtsAlarmThread extends Thread implements AlarmEventListener, LineListener{ public static final String cvsid = "$Id: RtsAlarmThread.java,v 1.1 2002/12/31 10:41:32 hwh Exp $"; Clip clip = null; AudioClip audioClip; URL completeURL; boolean looping = false; long alarmTime; String event_id = ""; public RtsAlarmThread( URL baseURL, boolean looping) { this.completeURL = baseURL; this.looping = looping; this.setName("RtsAlarmThread"); setPriority(MIN_PRIORITY); start(); } public RtsAlarmThread( URL baseURL ) { this( baseURL,false ); } public void alarmEventHandler(AlarmEvent e) { } public void run() { try { AudioInputStream ais = AudioSystem.getAudioInputStream(completeURL); AudioFormat format = ais.getFormat(); /** * we can't yet open the device for ALAW/ULAW playback, * convert ALAW/ULAW to PCM */ 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; } DataLine.Info info = new DataLine.Info( Clip.class, format, (int)(ais.getFrameLength()* format.getFrameSize())); clip = (Clip)AudioSystem.getLine(info); Thread.sleep(1000); clip.open(ais); clip.addLineListener(this); if (looping) { clip.loop(Clip.LOOP_CONTINUOUSLY); } else { clip.start();//Clip.LOOP_CONTINUOUSLY); } JOptionPane.showMessageDialog(null,event_id +" alarm at "+ new Date(alarmTime),"Event Alarm", JOptionPane.OK_OPTION); clip.stop(); clip.close(); } catch(Exception ex) { ex.printStackTrace(); } System.exit(0); } public void update(LineEvent event) { if (event.getType() != LineEvent.Type.STOP ) { System.err.println("Hello"); } } public static void main(String[] args) { URL codeBase = null; try { codeBase = new URL("file:/usr/local/jdk1.3.1/demo/sound/media/spacemusic.au"); } catch (MalformedURLException e) { System.err.println(e.getMessage()); } RtsAlarmThread t = new RtsAlarmThread(codeBase, true); } } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-java" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3E268198.2010401>