ciembor
ciembor

Reputation: 7337

Clip.stop() freeze for few seconds

I have a class Sample and Clip inside, written in Java. I'm playing it in loop:

public void play() {
  clip.loop(Clip.LOOP_CONTINUOUSLY);
}

I have also a stop method:

public void stop() {
  clip.stop();
}

and I want to stop it, when the new Sample instance is initialized (and starts to play) using Scala.

def setSample = {
  if (sample != null) {
    sample.stop
  }
  sample = new Sample(track, this)
  if (isPlay == true) {
    sample.play()
  }
}

The problem is, that clip.stop() hangs up for few seconds, so the next one isn't played immediately, as I expected. What can I do with that? And why it occurs?

//edit

I tried to use close() method and open clip again before new loop(). The same effect.

Upvotes: 3

Views: 639

Answers (1)

Gyula
Gyula

Reputation: 71

I'm not a Java/sound expert just did some spike previously. According to my tests and the literature the Java Sound API on Windows has some limitations. Hence if you are on Windows you may give ASIO a try to get a low latency playback solution. See: http://en.wikipedia.org/wiki/Audio_stream_input_output, specifically you will need the ASIO4ALL driver and the JAsioHost Java wrapper.

Upvotes: 1

Related Questions