播放音频剪辑时出现LineUnavailableException

时间:2018-08-01 17:20:11

标签: java linux

我正在尝试运行一些代码,以播放简单的音频剪辑。我正在尝试使用OpenJDK 1.8.0_172在Arch Linux中执行此操作。以root身份运行时,音频播放正常,但以普通用户身份运行时,则抛出LineUnavailableException。这里似乎存在权限问题,但我不知道这是什么。我已经将我的用户帐户添加到了音频组,但这并不影响它。任何建议将不胜感激。这是有问题的代码段:

try {
  // link an audio stream to the sound clip's file
  InputStream in = this.getClass().getResourceAsStream(fnm);
  InputStream bufferedIn = new BufferedInputStream(in);
  AudioInputStream stream = AudioSystem.getAudioInputStream(bufferedIn);     

  AudioFormat format = stream.getFormat();

  DataLine.Info info = new DataLine.Info(Clip.class, format);

  // make sure sound system supports data line
  if (!AudioSystem.isLineSupported(info)) {
    System.out.println("Unsupported Clip File: " + fnm);
    return;
  }

  // get clip line resource
  clip = (Clip) AudioSystem.getLine(info);

  // listen to clip for events
  clip.addLineListener(this);

  clip.open(stream);    // open the sound file as a clip
  stream.close(); // we're done with the input stream

  checkDuration();
} // end of try block
catch (LineUnavailableException noLineException) {
  System.out.println("No audio line available for : " + fnm);
}

对clip.open(stream)的调用引发了异常。

0 个答案:

没有答案