Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Every time I run a java application, one of two things happen:

  • Either I lose sound in all other programs (even after quitting the java app)
  • or if some other application is already playing sound, the said java app doesn't have sound

Usually this can be fixed by running pulseaudio --kill from the command line, but it doesn't always work.

Is there a way to fix this problem?

This didn't happen before the upgrade to karmic.

Other info:

  • The java I'm using is Sun's Java
share|improve this question
    
What's your sound hardware? Some drivers are awesome (e.g., emu10k1) and some are better avoided (e.g., cs46xx) –  Broam Dec 18 '09 at 15:26

5 Answers 5

up vote 3 down vote accepted
+300

This is a problem that plagued me for a while -- luckily I figured out a workaround. The first thing to do is

sudo apt-get install alsa-oss

Then basically, prefix "aoss" to any java-based commands you run. So,

java app

becomes

aoss java app

And so on. This should alleviate your issues. Cheers.

share|improve this answer
    
this works quite well, but it's still a work around. –  hasenj Dec 19 '09 at 1:11
    
Yeah, it's a workaround, but I have a suspicion that a "real solution" would involve modifying either Java's audio classes, or PulseAudio, either of which I'm guessing are more than you would be willing to do. This works well enough and I've encountered no problems using it for years :) –  Adrian Petrescu Dec 20 '09 at 3:08
    
+1 for a nice solution...err...workaround, sorry :D –  dag729 Dec 21 '09 at 1:22

Try this:

  1. Uninstall the alsa-base package
  2. sudo update-java-alternatives -s java-6-sun
    to use Sun's java rather than default Ubuntu java install

You must have Sun's java installed on your computer.

EDIT

Some links which might be useful:
Simple guide to Sound Solutions for Hardy,Intrepid and Jaunty Jackalope Users
Sound Solutions for Ubuntu 9.04 (Jaunty) Users

share|improve this answer
    
updated question: my java is sun's java. –  hasenj Dec 16 '09 at 7:45
    
Is it the latest version? –  harrymc Dec 16 '09 at 9:07
pulseaudio --kill

Is, as you said, only a (a little annoying) work around , may be you need something more radical, in my experiments with the "TERRIBLE" linux sound management, i've found that pulseaudio is more an issue than a solution, my advice is to ERADICATE it, using a punctual (and reversible, of course) procedure, i could write it, but i've found it here:

http://www.ubuntugeek.com/how-to-remove-pulse-audio-ubuntu-810-intrepid-ibex.html

Take this words "cum grano salis" even if was written for 8.10, trying to understand who are the parts interested on Linux audio management, maybe you can learn something. :-D

share|improve this answer

I know that is neither a workaround nor a solution, but it could help you to go one step straight to resolve the issue (at least so I hope): http://linux.dsplabs.com.au/lsof-grep-snd-how-to-free-a-linux-sound-device-p25/

It seems that Java need a sound device and so it grab one: the solution posted by Adrian Petrescu it's good. I would improve it using "aliases" in bashrc, something like "alias j='aoss java app'" could help.

Hope you could find a real solution (in such a case, I hope you'll write something upon the matter in some GREAT s because, as adrian said,

a "real solution" would involve modifying either Java's audio classes

Regards

share|improve this answer

This may not be an option for you, but OpenJDK on Ubuntu has in fact been modified to use PulseAudio by default. Switching to OpenJDK will make java sound "behave."

You could try configuring the Sun JRE to use the PulseAudio stuff from OpenJDK; the relevant configuration is in /usr/lib/jvm/java-6-openjdk/jre/lib/sound.properties and the code is in /usr/lib/jvm/java-6-openjdk/jre/lib/ext/pulse-java.jar. Copying those files to the corresponding location under /usr/lib/jvm/java-6-sun might work. Or it might not.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.