package greenfoot.sound;

import java.util.LinkedList;

import javax.sound.sampled.Clip;


| On OpenJDK/IcedTea (pulseaudio, 2012-03-26) it seems that clips take a long time to close | after they have finished playing. To prevent this from blocking us, we have a dedicated thread | (this class) to close old clips. | | @author Davin McCall | public class ClipCloserThread implements Runnable{ private LinkedList<Clip> clips = new LinkedList<Clip>(); private Thread thread; public ClipCloserThread() { } public void addClip(Clip clip) { synchronized (clips) { clips.add(clip); clips.notify(); if (thread == null || ! thread.isAlive()) { thread = new Thread(this); thread.setDaemon(true); thread.start(); } } } @Override public void run() { try { while (true){ Clip clip; synchronized (clips) { while (clips.isEmpty()){ clips.wait(); } clip = clips.removeFirst(); } clip.close(); } } catch (InterruptedException ie) { } } }
top, use, map, class ClipCloserThread

.   ClipCloserThread
.   addClip
.   run




61 neLoCode + 4 LoComm