0

I am trying to play an online WAV audio file from Java code.

My OS: Ubuntu 14.04. Java version: 8.

On my machine, it does play the file when I run the code from a stand alone java application.

But when I call this code from code that runs in Tomcat, I am getting the following exception:

Home directory not accessible: Permission denied
java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian is supported.
    at javax.sound.sampled.AudioSystem.getLine(AudioSystem.java:479)

Tomcat runs on my machine, as a service.

Why doesn't it work from Tomcat?

Community
  • 1
  • 1
rapt
  • 11,810
  • 35
  • 103
  • 145
  • *"On my machine, it does play the file when I run the code from a stand alone java application. But when I call this code from code that runs in Tomcat,.."* Wait ..what? Is that a server? If someone could connect from outside your network to the server, where would you expect the sound to be heard? The server machine or the client machine? – Andrew Thompson Mar 18 '16 at 09:32
  • @Andrew Thompson I expect the audio file to be played on the server machine. Just like sending text to the standard output. But when I test it, the server machine is my local machine. – rapt Mar 18 '16 at 12:05
  • Servers often run 'headless' which means they have no monitors and no speakers.. Check if Tomcat is running in headless mode. – Andrew Thompson Mar 18 '16 at 12:23
  • @Andrew Thompson I have changed Tomcat's settings to `JAVA_OPTS="-Djava.awt.headless=false ...` but still the same exception. – rapt Mar 19 '16 at 03:54

1 Answers1

0

Try to do a sudo chown -R 'username':'username' /home/'username' and then using pavucontrol to unmute the output. More information can be found here

Hossein
  • 1,152
  • 1
  • 16
  • 32
  • Why do you think it's a good idea to do so? I have many areas in my home that are owned by root. – rapt Mar 18 '16 at 01:15