Java Midi sequencer stops playing sound after several times. How to debug / resolve?

I am writing 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 call the playback method 19 times, the sound comes out of my speaker. However, 20 times when I call it, the sound does not come out. This always happens no matter what. I need to restart the program in order to get the sound again.

Is there any workaround? Or somehow debug this? Or in some place can I get support via the MIDI API?

+4
source share
1 answer

I do not know why he stops. Perhaps this is due to the fact that there are only 16 channels in midi, but instead of opening the sequencer several times, you can reuse the sequencer and change its 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(); } 
+3
source

All Articles