Note that there are some explanatory texts on larger screens.

plurals
  1. POJava problems playing sound clips
    primarykey
    data
    text
    <p>I have a problem playing a sound correctly in Java using the <a href="http://java.sun.com/j2se/1.5.0/docs/api/javax/sound/sampled/Clip.html" rel="nofollow noreferrer">Clip</a> interface.</p> <p>Playing the sound works using:</p> <pre><code>clip = (Clip)mixer.getLine(dataLineInfo); clip.open(audioFormat, byteData, 0, byteData.length); clip.start(); </code></pre> <p>However there is a memory leak if clips aren't closed.</p> <p>I have tried adding a line listener before starting the clip, and use the following code:</p> <pre><code>public void update(LineEvent e) { if (e.getType() == LineEvent.Type.STOP) { e.getLine().close(); </code></pre> <p>However, this causes the sound to degrage.</p> <p>Adding a 1 second sleep in the method makes things work again on my machine - but I would prefer a more elegant solution - I don't think waiting in a listener method is good practice and other machines may take longer.</p> <p>It is bizarre that the stop event is sent some time arbitrary time prior to the sound stopping.</p> <p>Does anyone have any ideas on a better way to solve this?</p> <p>(Related to <a href="https://stackoverflow.com/questions/557903/how-can-i-wait-for-a-java-sound-clip-to-finish-playing-back">this</a>, <a href="https://stackoverflow.com/questions/837974/determine-when-to-close-a-sound-playing-thread-in-java">this</a> and <a href="https://stackoverflow.com/questions/1816832/java-clip-sound-audio-memory-leak-after-closing-with-close">this</a> but none are solutions for me)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload