0

I am writing my Java program in Cloud9 IDE. I want to implement some kind of work with MP3 audio files. I downloaded and set up MP3SPI. I wrote simple test program, which uses this 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.
  }
 }

}

When I run it with java testmp I receive

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)

I tried turning on headless mode: java -Djava.awt.headless=true testmp. Received:

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

This application has no need in using display and/or keyboard, so I don't understand, why it uses X11. I found this solution of problem, however downloaded files were in archive.

How can I make it run in terminal? I have no need in playing MP3, I want to modify audio data (frames) and write it to other MP3 file.

Full error stack trace:

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)
Community
  • 1
  • 1
CactusZ
  • 3
  • 2

0 Answers0