如何创建一个静音选项 [英] How to create a mute option

查看:170
本文介绍了如何创建一个静音选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何创建一个静音切换为整个java应用程序?

How do I create a function that toggles mute for the whole java application?

其实所有的声音来自外部的小程序我在应用程序中加载。

Actually all the sound comes from an external applet I load in the application.

在code加载小程序是在这里:的https://github.com/Tyilo/RS2Lite/blob/master/src/com/rs2lite/loader/GameAppletLoader.java

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

推荐答案

有是端口使您可以访问计算机的调音台,但静音的声音会有静音所有声音的计算机。所以这可能不是一个很好的选择。

There is the Port which gives you access to the computer's mixer, but muting sound there would mute all sound of the computer. So that's probably not a good option.

除此之外,我相信,你需要现在效力的片段或的SourceDataLine的类的实例。最可能的是,然而,该小程序使用小程序的播放音​​频剪辑类,其可以或可以不内部使用一个剪辑/ SourceDataLine的...

Other than that, I believe that you require the class instance of the Clip or SourceDataLine that currently plays. Most probably, however, the applet uses Applet's AudioClip class for playback, which may or may not use a Clip/SourceDataLine internally...

无论如何,你可以试试下面的办法,应该对大多数Java声音实现工作:

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


  • 从AudioSystem,得到所有搅拌机

  • from AudioSystem, get all mixers

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

确认导入的javax.sound.sampled。*

make sure to import javax.sound.sampled.*

对于每个返回行,尽量使静音控制:

for each returned line, try to get the Mute control:

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


请注意,有没有保证,你会得到线,并不能保证声音的Java实现提供了一个给定行的静音控制。

Note that there is no guarantee that you will get lines, and no guarantee that the Java Sound implementation provides the MUTE control for a given line.

这篇关于如何创建一个静音选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆