我正在编写一些代码,这些代码在运行时会自动开始播放 MIDI 序列,并且用户可以随时通过按键暂停。他们的关键事件处理工作得很好,但是,我遇到了一个非常奇怪的错误,其中暂停了音序器:
public void pause() {
// if the sequencer is playing, pause its playback
if (this.isPlaying) {
this.sequencer.stop();
} else { // otherwise "restart" the music
this.sequencer.start();
}
this.isPlaying = !this.isPlaying;
}
重置音序器的速度。歌曲/音序器以 120000 MPQ 开始播放(从我的输入加载)并重置为 500000 MPQ。有谁知道为什么会发生这种情况?谢谢。
最佳答案
事实证明,调用 start() 会将音序器的速度重置为默认值 500000 mpq。对于遇到同样问题的任何人,解决方案如下:
public void pause() {
// if the sequencer is playing, pause its playback
if (this.isPlaying) {
this.sequencer.stop();
} else { // otherwise "restart" the music
// store the tempo before it gets reset
long tempo = this.sequencer.getTempoInMPQ();
// restart the sequencer
this.sequencer.start();
// set/fix the tempo
this.sequencer.setTempoInMPQ(tempo);
}
this.isPlaying = !this.isPlaying;
}
关于java - 暂停 Java Sequencer 重置节奏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37935814/