Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ZimbraTray, SoundOptionsForm: release audio resources when sound clip…
… is done
  • Loading branch information
pfn committed Nov 3, 2009
1 parent 626463c commit b5f09c6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/java/com/zimbra/app/systray/ZimbraTray.java
Expand Up @@ -35,6 +35,8 @@
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem;
Expand Down Expand Up @@ -584,7 +586,13 @@ public void playSound(String name) {
File f = new File(name);
fin = new FileInputStream(f);
AudioInputStream ain = AudioSystem.getAudioInputStream(fin);
Clip audioClip = AudioSystem.getClip();
final Clip audioClip = AudioSystem.getClip();
audioClip.addLineListener(new LineListener() {
public void update(LineEvent e) {
if (LineEvent.Type.STOP == e.getType())
audioClip.close();
}
});
audioClip.open(ain);
audioClip.start();
}
Expand Down
Expand Up @@ -164,6 +164,7 @@ private void stopClip() {
if (audioClip != null) {
if (audioClip.isRunning())
audioClip.stop();
audioClip.close();
audioClip = null;
}
}
Expand Down

0 comments on commit b5f09c6

Please sign in to comment.