暂停Java Sequencer可重置速度

暂停Java Sequencer可重置速度,java,reset,midi,javax.sound.midi,tempo,Java,Reset,Midi,Javax.sound.midi,Tempo,我正在编写一些代码,当运行时,会自动开始播放midi序列,用户可以通过按键随时暂停。他们的关键事件处理工作得很好,但是,我得到了一个非常奇怪的错误,暂停sequencer时使用: public void pause() { // if the sequencer is playing, pause its playback if (this.isPlaying) { this.sequencer.stop(); } else { // otherwise

我正在编写一些代码,当运行时,会自动开始播放midi序列,用户可以通过按键随时暂停。他们的关键事件处理工作得很好,但是,我得到了一个非常奇怪的错误,暂停sequencer时使用:

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;
}

停止不是暂停。实现中的代码为什么会这样做,只有作者知道。