Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mute sound in Java Applet

I use a Java applet, which produces unwanted sounds to me. Mute option in the applet is missing, and it's not possible to rewrite the source code. I want to hear other(non-JVM) applications' sounds. How do I suppress this Java applet(or JVM) sound output without disabling it?

I'm using Ubuntu 9.10, jre1.6.0_18 and Mozilla FF 3.5.8.

UPDATE:

  1. Java applet is missing in "Sound preferences->Applications", because sounds are too short("beep" etc.).
  2. When other application produces sounds(.mp3, .ogg music) java applet doesn't.
like image 840
INeedUrHelpRly Avatar asked Feb 20 '10 02:02

INeedUrHelpRly


2 Answers

If you are in control of the deployment of the applet (I.e. the webpage hosting the applet), you could write your own Applet Launcher. The launcher functions as a wrapper that provides a custom environment to the actual applet. The launcher instantiates the real applet and passes to it customized versions of the applet environment (AppletStub, AppletContext.) The custom environment implements AudioClip as a "do nothing" interface.

To disable audio, you could override the AppletContext like this:

class CustomAppletContext implements AppletContext
{
    AppletContext realContext;

    // most methods delegate to the real context, either directly, or with a little modification to hide the fact that we are using this launcher
   public void setStatus(String status)
   {
       realContext.setStatus(status);
   }

   // override the getAudioClip to return a dummy clip
   public AudioClip getAudioClip(URl url)
   {
       return new DummyAudioClip();
   }
}

// An AudioClip implementation that does nothing
class DummyAudioClip implements AudioClip
{
    public void loop() { }
    public void play() { }
    public void stop() { }
}

We also override AppletStub, since this is where the Applet gets the AppletContext from

class CustomAppletStub implements AppletStub
{
    AppletStub realStub;

    public AppletContext getAppletContext()
    {
        return new CustomAppletContext(realStub.getAppletContext());
    }
}

And then, your launcher:

class AppletLauncher extends Applet
{
    private Applet   realApplet = new NoisyApplet();

    // delegate most methods to the applet, but override the stub, to inject our
    // AppletContext and AudioClip implementation

    public void setAppletStub(AppletStub stub)
    {
        realApplet.setAppletStub(new CustomAppletStub(stub));
    }
}

It looks like a lot of code, but it's really just a few classes and mostly wiring just to inject a new DummyAudioClip implementation.

HTH!

like image 102
mdma Avatar answered Oct 07 '22 03:10

mdma


probably should be in power user. You can use pulse audio to control applications sounds(assuming you haven't disabled it) it should be in sound preferences. right click on the volume applet and open preferences click on application tab.

like image 39
Roman A. Taycher Avatar answered Oct 07 '22 02:10

Roman A. Taycher