Clip.stop() 冻结几秒钟
我里面有一个类 Sample 和 Clip,是用 Java 编写的。我正在循环播放它:
public void play() {
clip.loop(Clip.LOOP_CONTINUOUSLY);
}
我还有一个停止方法:
public void stop() {
clip.stop();
}
当使用 Scala 初始化(并开始播放)新的 Sample 实例时,我想停止它。
def setSample = {
if (sample != null) {
sample.stop
}
sample = new Sample(track, this)
if (isPlay == true) {
sample.play()
}
}
问题是,clip.stop() 挂起几秒钟,所以下一个不会像我预期的那样立即播放。我能用它做什么呢?以及为什么会出现这种情况?
//编辑
我尝试使用 close() 方法并在 new Loop() 之前再次打开剪辑。效果一样。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 Java/声音专家,只是之前做过一些尖峰。根据我的测试和文献,Windows 上的 Java Sound API 有一些限制。因此,如果您使用的是 Windows,您可以尝试 ASIO 以获得低延迟播放解决方案。请参阅:http://en.wikipedia.org/wiki/Audio_stream_input_output,具体来说,您将需要ASIO4ALL 驱动程序和 JAsioHost Java 包装器。
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.