在我的客户端上,我试图让 MIDI 文件淡出,然后再继续处理序列中的下一个 MIDI,但我一直遇到问题。
使用下面的代码,它会导致 nullpointerException track.add
,我想知道我做错了什么?
我对Java编程比较陌生,所以请具体回答
public void run() {
active = true
String s = findcachedir();
uid = getuid(s);
if(midiplay)
{
/*
midi = s + savereq;
midiplay = false;
*/
midi = s + savereq;
try {
//System.out.println("Play MIDI " + midi);
if (musicSr != null)
{
musicSr.stop();
musicSr.close();
}
musicSr = null;
musicS = null;
File music = new File(midi);
if(music.exists())
{
musicS = MidiSystem.getSequence(music);
}
for (int k = 0; k < 16; k++) {
musicS.getTracks();
track.add(
new MidiEvent(
new ShortMessage(
ShortMessage.CONTROL_CHANGE,
k,
7,
20),
track.getTicks()));
}
// Create a sequencer for the sequence
musicSr = MidiSystem.getSequencer();
musicSr.open();
musicSr.setSequence(musicS);
musicSr.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
musicSr.start();
} catch (Exception ex) {
ex.printStackTrace();
}
midiplay = false;
}
savereq = null;
}
}
public static Sequencer musicSr = null;
Sequence musicS = null;
` 整个班级,如果您出于任何原因需要它