简体   繁体   English

Java Midi音序器在几次后停止发出声音。 我该如何调试/解决?

[英]Java Midi sequencer stops producing sound after a few times. How do I debug/resolve?

I'm writing some code to play music using the Java sound library. 我正在编写一些代码来使用Java声音库播放音乐。

private Sequencer sequencer ;
...
void play(Sequence sequence) {
    sequencer.open() ;
    sequencer.setSequence(sequence) ;
    sequencer.start() ; // plays sequence
    sequencer.close() ;
}

When I invoke the play method 19 times, sound comes out of my speaker. 当我调用播放方法19次时,声音从我的扬声器中传出。 However, the 20th time I invoke it, no sound comes out. 然而,第20次我调用它,没有声音出来。 This always happens, no matter what. 无论如何,这总是会发生。 I need to restart the program to get sound again. 我需要重新启动程序才能再次获得声音。

Is there some workaround for this issue? 这个问题有一些解决方法吗? Or some way to debug this? 或者某种方式调试这个? Or some place I can get support on the MIDI sound API? 或者某些地方我可以获得MIDI声音API的支持?

I don't know why it stops. 我不知道为什么会停止。 Maybe it has something to do with there being only 16 channels in midi, but rather than opening the sequencer multiple times, you can reuse the sequencer and change it's sequence. 也许它与midi中只有16个通道有关,但不是多次打开音序器,你可以重复使用音序器并改变它的序列。 This is what I have and it works for me: 这就是我所拥有的,它对我有用:

public void play(Sequence sequence) {
    sequencer.setSequence(sequence);
    sequencer.stop();
    sequencer.setTickPosition(0);
    sequencer.start();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM