Mac OSX 中的 Java Midi 损坏了吗?
我正在尝试在浏览器中播放 midi,并且一直在使用在 PC 上运行良好的 Java Applet。它在 OSX 上极其不可靠,所以我写了一个简单的测试用例,它表现出同样的问题:
import javax.sound.midi.*;
import java.io.InputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class MidiPlayer {
public static void main(String[] args) {
try {
Sequencer sequencer = MidiSystem.getSequencer();
if (sequencer == null)
throw new MidiUnavailableException();
sequencer.open();
FileInputStream is = new FileInputStream("sample.mid");
Sequence mySeq = MidiSystem.getSequence(is);
sequencer.setSequence(mySeq);
sequencer.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
听起来偶尔的消息被丢弃了。就像一个音符不会触发,而一个随机音符将永远挂起。这是 OSX 中的已知问题吗?如今,Java 似乎没有得到 Apple 足够的喜爱。
如果有人有更好的解决方案在浏览器中播放 Midi,我会洗耳恭听!
I'm trying to play midi within a browser, and have been using a Java Applet that works just fine on PCs. Its extremely unreliable on OSX, so I wrote a simple test case that exhibits the same problem:
import javax.sound.midi.*;
import java.io.InputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class MidiPlayer {
public static void main(String[] args) {
try {
Sequencer sequencer = MidiSystem.getSequencer();
if (sequencer == null)
throw new MidiUnavailableException();
sequencer.open();
FileInputStream is = new FileInputStream("sample.mid");
Sequence mySeq = MidiSystem.getSequence(is);
sequencer.setSequence(mySeq);
sequencer.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
It sounds like the occasional message is getting dropped.. Like a noteoff won't fire, and a random note will hang on forever. Is this a known problem in OSX? Seems like Java just isn't getting enough love from Apple these days.
If anyone has a better solution to playing Midi in a browser, I'm all ears!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎是一个由两部分组成的问题。我也无法使用 2011 年中期配备 OSX 10.7.5 的 iMac 发送 MIDI sysex。我确实找到了一个解决方法 - 首先,我必须使用 mmj jar 和 jnilib,其次我必须告诉我的代码使用时间戳 -1 而不是使用 system.currentTimeMillis()。就我而言,我正在发送实时 sysex 消息,因此 -1 的时间戳适合我。如果您正在处理 MIDI 音符开/关等问题,我不知道要使用什么时间戳。也许时间戳是未来的毫秒数?我不知道。但我确实知道我必须同时使用 mmj 并更好地控制我的时间戳。之后,事情就会按预期进行。
This appears to be a two part problem. I too could not send midi sysex's using a mid-2011 OSX 10.7.5 equipped iMac. I did find a workaround - first, I had to use the mmj jar and jnilib's and secondly I had to tell my code to use timestamps of -1 and NOT to use system.currentTimeMillis(). In my case I'm sending realtime sysex messages, thus a timestamp of -1 works for me. I don't know what timestamp to use if you're dealing with midi note on/off's etc. Perhaps the timestamp is milliseconds into the future? I don't know. But I do know that I had to use both mmj and take better control of my timestamps. After that, things work as expected.
来自 mmj - Mac OS X 上的 java Midi:
OS X 上的 MIDI 情况似乎很糟糕,尽管该 API 是作为替代品提供的。
From mmj - Midi for java on Mac OS X:
The situation on OS X seems dire re MIDI, though that API is offered as a replacement.