开发者

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

开发者 https://www.devze.com 2023-03-07 13:13 出处:网络
I\'m writing some code to play music using the Java sound library. private Sequencer sequencer ; ... void play(Sequence sequence) {

I'm writing some code to play music using the Java sound library.

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. However, the 20th time I invoke it, no sound comes out. 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 MID开发者_JS百科I sound 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. 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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消