小编Sto*_*r9k的帖子

Java声音:在IntelliJ中运行但在SBT中找不到的设备

我正在尝试在Scala SBT管理的项目中使用Java Sound API。

这是一个可播放音符的玩具应用。

import javax.sound.midi._

object MyMain extends App {
  val infos = MidiSystem.getMidiDeviceInfo()
  println( "[DEBUG] midi devices found: " + infos.length )

  val myMsg = new ShortMessage;
  // Start playing the note Middle C (60),
  // moderately loud (velocity = 93).
  myMsg.setMessage(ShortMessage.NOTE_ON, 0, 60, 93);
  val timeStamp = -1;
  val rcvr : Receiver = MidiSystem.getReceiver();
  rcvr.send(myMsg, timeStamp);

  readChar()  // give time to play note
}
Run Code Online (Sandbox Code Playgroud)

当我run在SBT中执行时,我得到的javax.sound.midi.MidiUnavailableException因为 infos.length返回0。也就是说,当我在IntelliJ中运行该应用程序时,发现了两个设备,并且该音符的播放效果很好。

SBT要使其运行需要知道什么?是否有需要添加到类路径的东西?我注意到IntelliJ将一大堆jar附加到执行命令(但是,删除来自jdk / jre / lib …

java scala intellij-idea javasound

3
推荐指数
1
解决办法
514
查看次数

标签 统计

intellij-idea ×1

java ×1

javasound ×1

scala ×1