2016-06-21 2 views
1

실행 중일 때 MIDI 시퀀스 재생을 자동으로 시작하고 사용자가 키를 눌러 언제든지 일시 중지 할 수있는 코드를 작성 중입니다. 그들은 키 이벤트와 시퀀서를 일시 중지 어디 그러나, 내가, 아주 이상한 오류를 받고 있어요, 잘 일을 처리 :Java 시퀀서 일시 중지

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로 재설정됩니다. 왜 이런 일이 일어날 지 아는 사람이 있습니까? 감사.

+0

중지가 중지되지 않습니다. 그리고 여러분의 구현에서이 코드가 작성자에 의해서만 알려진 이유는 무엇입니까? –

답변

0

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; 
} 
관련 문제