Using JavaSounds from tomcat

泪湿孤枕 提交于 2019-12-12 01:37:37

问题


I'm trying to write a Java EE application that records sound from the input on the server. My code works fine when debuging, and running on the server as myself (both ubuntu) however when it's running from the web sever I get an exception:

javax.sound.sampled.LineUnavailableException
at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openImpl(PulseAudioMixer.java:714)
at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openLocal(PulseAudioMixer.java:588)
at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openLocal(PulseAudioMixer.java:584)
at org.classpath.icedtea.pulseaudio.PulseAudioMixer.open(PulseAudioMixer.java:579)
at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:95)
at org.classpath.icedtea.pulseaudio.PulseAudioTargetDataLine.open(PulseAudioTargetDataLine.java:111)
at org.classpath.icedtea.pulseaudio.PulseAudioTargetDataLine.open(PulseAudioTargetDataLine.java:130)

I've tried to add the tomcat user to the audio group (which some documentation suggested) but it's still throwing the exception. I think the only difference must be the environment, but I'm at a loss for where the problem might be.


回答1:


I'm assuming that you've got the appropriate JARs in the CLASSPATH - either in your application WEB-INF/lib or in the Tomcat /lib.

The fact that you're trying to open something suggests that maybe you have a path problem. Web apps can't depend on an absolute file path, because they can't know where a WAR file will be installed. So it's better to use a relative path and get resources as streams. Perhaps there's a way to do it with this library.




回答2:


I've managed to get this working now - but thank for the help.

In the end it was a OS level issue, under ubuntu only users in the audio group can access sound resources when not logged in (https://wiki.ubuntu.com/Audio/TheAudioGroup) and to connect to pulse audio it looks like you need X11 auth of some kind. After those changes it require a restart so tomcat could grab the sound device before anything else did.



来源:https://stackoverflow.com/questions/7046011/using-javasounds-from-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!