简单的Java MIDI示例不产生任何声音 [英] Simple Java MIDI example not producing any sound

查看:100
本文介绍了简单的Java MIDI示例不产生任何声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个简单的代码在我用来测试它的几台机器上没有产生任何声音.我正在Eclipse中运行代码,但我也尝试使用命令行无济于事.

This simple code is not producing any sound on a couple of machines that I've used to test it. I'm running the code from within Eclipse, but I've also tried using the command line to no avail.

public static void main(String[] args)
{
    try {
        Synthesizer synthesizer = MidiSystem.getSynthesizer();
        synthesizer.open();

        MidiChannel[] channels = synthesizer.getChannels();

        channels[0].noteOn(60, 60);
        Thread.sleep(200);
        channels[0].noteOff(60);

        synthesizer.close();
    } catch (Exception e)
    {
        e.printStackTrace();
    }
}

我能够通过获取音序器,将MIDI事件添加到音序并播放音序来成功获取声音,但是我正在尝试做一些音序器不支持的实时音乐效果.

I am able to successfully get sound by getting a Sequencer, adding MIDI events to the sequence, and playing the sequence, but I'm trying to do some real-time music effects, which the sequencer does not support.

有什么想法吗?

使用解决方案进行事实证明,问题在于,默认情况下,JRE不带有音库(有趣的是,使用Sequencer起作用了,但是使用Synthesizer却没有了) ').谢谢, thejmc

EDIT WITH SOLUTION: It turns out the problem is that, by default, the JRE doesn't come with a soundbank (interesting, then, that using the Sequencer worked, but using the Synthesizer didn't). Thanks, thejmc!

为解决此问题,我从java.sun下载了音色库.com 并将其放在(在WinXP上)C:\ Program Files \ jre1.6.0_07 \ lib \ audio(必须创建音频文件夹)中.

To solve the problem, I downloaded a soundbank from java.sun.com and placed it in (on WinXP) C:\Program Files\jre1.6.0_07\lib\audio (had to make the audio folder).

推荐答案

JRE的某些安装不包含JavaSound soundbank.gm(为了节省空间),因此您的代码将没有声音源来触发这些声音机器.

Some installs of the JRE do not include the JavaSound soundbank.gm (in order to save space) so your code would not have a sound source to trigger on those machines.

检查无法运行的机器上是否存在音库.您也可以将音库与.class文件放在同一目录中,然后它将找到它.

Check for the existence of the soundbank on the machines that don't work. You can also put the soundbank in the same directory as your .class file and it will find it.

可以在这些机器上添加音库或升级Java安装-不一致的痛苦,我知道:)

It is possible to add the soundbank or to upgrade the Java install on those machine - the pain of inconsistency, I know :)

这篇关于简单的Java MIDI示例不产生任何声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆