无法发送MIDI文件名的Java播放音乐 [英] Unable to send MIDI file name to Java to playback music
本文介绍了无法发送MIDI文件名的Java播放音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以播放MIDI文件,其中名与asd.mid值的String类型。不过,我想送空气的的NativeProcess命令去渣,它显示无法读取错误。怎么会呢?
Java的:
私人无效playMidi(){
如果(isPlaying.equals(0)){
尝试 {
歌= MidiSystem.getSequence(新文件(文件名));
定序= MidiSystem.getSequencer();
sequencer.setSequence(歌曲);
sequencer.open();
sequencer.addMetaEventListener(本);
sequencer.start();
}赶上(InvalidMidiDataException E){
的System.out.println(坏MIDI文件:+文件名);
System.exit(1);
}赶上(MidiUnavailableException E){的System.out.println(无可用序);
System.exit(1);
}赶上(IOException异常E){的System.out.println(无法读取:+文件名);
System.exit(1);
}
displayMidiInfo(文件名);
} 其他 {
updateTempoFactor(速度);
}
}
解决方案
使用一个相对路径,另一个是绝对的?除非这两个应用程序都坐在同一个文件夹中,我想像你需要的文件路径,而不仅仅是文件名。
I could play MIDI file where "filename" is a String type with "asd.mid" value. However, I tried to sent AIR's nativeprocess command to Java, it shown "could not read" error. How come?
Java:
private void playMidi() {
if(isPlaying.equals("0")) {
try {
song = MidiSystem.getSequence(new File(filename));
sequencer = MidiSystem.getSequencer();
sequencer.setSequence(song);
sequencer.open();
sequencer.addMetaEventListener(this);
sequencer.start();
} catch (InvalidMidiDataException e) {
System.out.println("Bad midi file: "+ filename);
System.exit(1);
} catch (MidiUnavailableException e) {System.out.println("No sequencer available");
System.exit(1);
} catch (IOException e) {System.out.println("Could not read: "+ filename);
System.exit(1);
}
displayMidiInfo(filename);
} else {
updateTempoFactor(speed);
}
}
解决方案
Is one using a relative path and the other an absolute? Unless both applications are sitting in the same folder, I'd imagine you'd need the filepath rather than just the filename.
这篇关于无法发送MIDI文件名的Java播放音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文