如何使用Java播放默认的Windows OS(不仅是)“完成/完成”声音?还是应该使用一些准备好的声音文件?也许我应该从某些注册表值中获取声音文件的位置?
我发现Windows操作系统有以下可能性:
String propnames[] = (String[]) Toolkit.getDefaultToolkit().getDesktopProperty("win.propNames");
System.out.println("Supported windows property names:");
for (int i = 0; i < propnames.length; i++) {
System.out.println(propnames[i]);
}
输出:
(...)
win.sound.asterisk
win.sound.close
win.sound.default
win.sound.exclamation
win.sound.exit
win.sound.hand
win.sound.maximize
win.sound.menuCommand
win.sound.menuPopup
win.sound.minimize
win.sound.open
win.sound.question
win.sound.restoreDown
win.sound.restoreUp
win.sound.start
(...)
再例如:
Runnable runnable = (Runnable) Toolkit.getDefaultToolkit().getDesktopProperty("win.sound.exclamation");
if (runnable != null) runnable.run();
其他系统怎么样?
另外,也可以是:
try {
try (Synthesizer synthesizer = MidiSystem.getSynthesizer()) {
synthesizer.open();
MidiChannel[] channels = synthesizer.getChannels();
channels[0].noteOn(60, 60);
Thread.sleep(2000);
channels[0].noteOff(60);
}
} catch (InterruptedException | MidiUnavailableException ex) {
Logger.getLogger(TestIt.class.getName()).log(Level.SEVERE, null, ex);
}
但是在这里,我必须创建自己的乐队并发行所有时间以来最伟大的单曲:)
最佳答案
是的,您处在正确的轨道上,可以使用以下方式播放系统声音:
Toolkit.getDefaultToolkit().getDesktopProperty("win.sound.exclamation");
或发出哔声(在Mac OS中也适用):
Toolkit.getDefaultToolkit().beep();
关于java - 如何使用Java播放默认Windows OS(不仅是) “finish/completed”声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29162930/