有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

音频java。awt。MP3SPI中的无头异常

我正在用Cloud9IDE编写Java程序。我想实现一些MP3音频文件的工作。我下载并设置了MP3SPI。我编写了一个简单的测试程序,它使用这个API

import javax.sound.sampled.*;
import java.io.*;

public class testmp {


 public static void main(String[] args) {
  testPlay("../../tmp_mp3/Redfoo.mp3");
 }

 public static void testPlay(String filename) {
  try {
   File file = new File(filename);
   AudioInputStream in = AudioSystem.getAudioInputStream(file);
   AudioInputStream din = null;
   AudioFormat baseFormat = in .getFormat();
   AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
    baseFormat.getSampleRate(),
    16,
    baseFormat.getChannels(),
    baseFormat.getChannels() * 2,
    baseFormat.getSampleRate(),
    false);
   din = AudioSystem.getAudioInputStream(decodedFormat, in ); in .close();
  } catch (Exception e) {
   //Handle exception.
  }
 }

}

当我用java testmp运行它时,我收到

java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:207)

我试着打开无头模式:java -Djava.awt.headless=true testmp。收到:

java.awt.HeadlessException
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:207)

这个应用程序不需要使用显示器和/或键盘,所以我不明白为什么它使用X11。 我找到了问题的this解决方案,但下载的文件在存档中

我怎样才能让它在航站楼运行?我不需要播放MP3,我想修改音频数据(帧)并将其写入其他MP3文件

完整错误堆栈跟踪:

java.awt.HeadlessException
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:207)
        at java.awt.Window.<init>(Window.java:535)
        at java.awt.Frame.<init>(Frame.java:420)
        at java.awt.Frame.<init>(Frame.java:385)
        at com.trend.iwss.jscan.runtime.BaseDialog.getActiveFrame(BaseDialog.java:75)
        at com.trend.iwss.jscan.runtime.AllowDialog.make(AllowDialog.java:32)
        at com.trend.iwss.jscan.runtime.PolicyRuntime.showAllowDialog(PolicyRuntime.java:325)
        at com.trend.iwss.jscan.runtime.PolicyRuntime.stopActionInner(PolicyRuntime.java:240)
        at com.trend.iwss.jscan.runtime.PolicyRuntime.stopAction(PolicyRuntime.java:172)
        at com.trend.iwss.jscan.runtime.FileIOPolicyRuntime.doStopAction(FileIOPolicyRuntime.java:281)
        at com.trend.iwss.jscan.runtime.FileIOPolicyRuntime._preFilter(FileIOPolicyRuntime.java:260)
        at com.trend.iwss.jscan.runtime.PolicyRuntime.preFilter(PolicyRuntime.java:132)
        at com.trend.iwss.jscan.runtime.FileIOPolicyRuntime.preFilter(FileIOPolicyRuntime.java:171)
        at com.sun.media.codec.audio.mp3.JS_MP3FileReader.getAudioInputStream(JS_MP3FileReader.java:113)
        at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1179)
        at testmp.testPlay(testmp.java:16)
        at testmp.main(testmp.java:9)

共 (0) 个答案