How to create a mute option

How to create a function that mutes the sound for the whole java application?

In fact, all the sound comes from an external applet loaded into the application.

The code for downloading the applet is here: https://github.com/Tyilo/RS2Lite/blob/master/src/com/rs2lite/loader/GameAppletLoader.java

+4
source share
1 answer

There is a Port that gives you access to a computer mixer, but a muffled sound mutes your computer. So this is probably not a very good option.

In addition, I believe that you need an instance of the Clip or SourceDataLine class that is currently playing. Most likely, however, the applet uses the Applet AudioClip class to play, which may or may not use Clip / SourceDataLine inside ...

In any case, you can try the following approach, it should work on most Java Sound implementations:

  • from AudioSystem, get all mixers

     Mixer.Info[] infos = AudioSystem.getMixerInfo(); for (Mixer.Info info: infos) { Mixer mixer = AudioSystem.getMixer(info); } 

    be sure to import javax.sound.sampled. *

  • from each mixer, extract the getSourceLines() using getSourceLines()
  • for each row returned, try getting a mute control:

     BooleanControl bc = (BooleanControl) line.getControl(BooleanControl.Type.MUTE) if (bc != null) { bc.setValue(true); // true to mute the line, false to unmute } 

Note that there is no guarantee that you will receive strings, and you cannot guarantee that the Java Sound implementation provides MUTE control for a given string.

+4
source

All Articles