Follow in your code example.
When some midi files is play to the end of the play time, the MIDIPlayer.play() call back did not properly execute "play ended", instead when I tried to click pause and resume, my ears was blasted with extreme loud noise with 100+ notes at the same time.
Need to reset play time correctly at the end of the song.