MidiUnavailableException在Java中? [英] MidiUnavailableException in Java?

查看:342
本文介绍了MidiUnavailableException在Java中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些麻烦,播放MIDI文件在Java中。我得到的是一个 MidiUnavailableException(MIDI OUT发射不可用)当我尝试播放它。我的code是标准的:

  {尝试
    midiseq = MidiSystem.getSequencer();
    midiseq.open();
    midiseq.setSequence(MidiSystem.getSequence(Sound1例子));
    midiseq.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
    midiseq.start();
}赶上(例外五){e.printStackTrace();}

midiseq ; Sound1例子的InputStream

这code适用于其他几台电脑,甚至是工作在Eclipse和JAR文件使用时,只是没有当我从命令提示符启动它。我下载了一个更稳定的Java MIDI应用程序,它抛出同样的异常。

这不可能是一个硬件问题,因为Eclipse可以运行没有问题的,既没有因为这可以正常运行在其他计算机上它可以是一个编码问题。即使code的这一行抛出此异常:

  javax.sound.midi.MidiSystem.getSequencer();

先谢谢了。

编辑:我的操作系统是Windows Vista中。之前我问这个问题我已经下载了最新的JRE和JDK(1.6.0_13我认为)。

编辑:code:

  ClassLoader.getSystemClassLoader()的loadClass(com.sun.media.sound.RealTimeSequencer);
的System.out.println(序类加载); //否则的ClassNotFoundException

打印序类加载的。

但是,这code:

  {尝试
        的System.out.println(javax.sound.midi.MidiSystem.getSequencer());
        System.exit(0);
      }赶上(例外五){
        抛出新的RuntimeException(E);
      }
      System.exit(1);

MidiUnavailableException。

此外,这code:

  MidiDevice.Info [] =设备MidiSystem.getMidiDeviceInfo();
如果(devices.length == 0){
的System.out.println(找不到MIDI设备);
}其他{
对于(MidiDevice.Info开发:设备){
的System.out.println(DEV);
}
}

给我这样的:


    微软MIDI映射
    微软GS波形表合成器
    实时测序
    Java的声音合成器


解决方案

首先看一下你的系统的功能:

  MidiDevice.Info [] =设备MidiSystem.getMidiDeviceInfo();
如果(devices.length == 0){
    的System.out.println(找不到MIDI设备);
}其他{
    对于(MidiDevice.Info开发:设备){
        的System.out.println(DEV);
    }
}

如果有什么都没有,你可能需要安装音库以使
JVM来创建软件音序器。

另外,请检查MidiSystem.getReceiver()的输出作为可怕MidiUnavailableException如果一个接收器无法创建也会发生(<一个href=\"http://java.sun.com/j2se/1.5.0/docs/api/javax/sound/midi/MidiSystem.html#getSequencer%28boolean%29\"相对=nofollow> MidiSystem的javadoc )。

我希望安装音库文件将给JVM依傍合成接收器的机会,而不是需要硬件的访问了(这似乎是失败的:)

I'm having some trouble playing MIDI files in Java. What I get is a MidiUnavailableException (MIDI OUT transmitter not available) when I try to play it. My code is standard:

try {
    midiseq = MidiSystem.getSequencer();
    midiseq.open();
    midiseq.setSequence(MidiSystem.getSequence(sound1));
    midiseq.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
    midiseq.start();
} catch (Exception e) {e.printStackTrace();}

midiseq is a Sequencer; sound1 is an InputStream.

This code works on several other computers, and even works in Eclipse and when used in a JAR file, just not when I launch it from the command prompt. I've downloaded a more stable Java midi application, and it threw the same exception.

It can't be a hardware problem because Eclipse can run it without problems, neither can it be a coding problem because this runs correctly on other computers. Even this one line of code throws this exception:

javax.sound.midi.MidiSystem.getSequencer();

Thanks in advance.

edit: My operating system is Windows Vista. Before I asked this question I've downloaded the latest JRE and JDK (1.6.0_13 I think).

edit: The code:

ClassLoader.getSystemClassLoader().loadClass("com.sun.media.sound.RealTimeSequencer");
System.out.println( "Sequencer class loaded" );// Otherwise ClassNotFoundException

prints "Sequencer class loaded."

But this code:

  try{
        System.out.println(javax.sound.midi.MidiSystem.getSequencer());
        System.exit(0);
      } catch(Exception e) {
        throw new RuntimeException(e);
      }
      System.exit(1);

throws the MidiUnavailableException.

Also, this code:

	MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
	if (devices.length == 0) {
	    System.out.println("No MIDI devices found");
	} else {
	    for (MidiDevice.Info dev : devices) {
	        System.out.println(dev);
	    }
	}

gives me this:

    Microsoft MIDI Mapper
    Microsoft GS Wavetable Synth
    Real Time Sequencer
    Java Sound Synthesizer

解决方案

First have a look at the capabilities of your system:

MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
if (devices.length == 0) {
    System.out.println("No MIDI devices found");
} else {
    for (MidiDevice.Info dev : devices) {
        System.out.println(dev);
    }
}

If there is nothing there, you might need to install soundbanks to enable the jvm to create a software sequencer.

Also check the output of MidiSystem.getReceiver() as the dreaded MidiUnavailableException will also occur if a receiver can not be created (MidiSystem javadoc).

I expect that installing the soundbank file will give the jvm the opportunity to fall back on a synthesizer receiver, and not require hardware access anymore (which seems to fail:)

这篇关于MidiUnavailableException在Java中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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