Java Applet 中的静音

发布于 2024-08-22 02:25:13 字数 302 浏览 5 评论 0原文

我使用 Java 小程序,它会产生我不想要的声音。 小程序中缺少静音选项,并且无法重写源代码。 我想听听其他(非 JVM)应用程序的声音。 如何在不禁用此 Java applet(或 JVM)声音输出的情况下抑制它?

我使用的是 Ubuntu 9.10、jre1.6.0_18 和 Mozilla FF 3.5.8。

更新:

  1. “声音首选项 -> 应用程序”中缺少 Java 小程序,因为声音太短(“蜂鸣声”等)。
  2. 当其他应用程序产生声音(.mp3、.ogg 音乐)时,java 小程序不会。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

北座城市 2024-08-29 02:25:13

如果您可以控制小程序的部署(即托管小程序的网页),您可以编写自己的小程序启动器。启动器充当包装器,为实际小程序提供自定义环境。启动器实例化真正的小程序,并将小程序环境的自定义版本(AppletStub、AppletContext)传递给它。自定义环境将 AudioClip 实现为“不执行任何操作”接口。

要禁用音频,您可以像这样重写 AppletContext:

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() { }
}

我们还重写 AppletStub,因为这是 Applet 从中获取 AppletContext 的地方

class CustomAppletStub implements AppletStub
{
    AppletStub realStub;

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

然后,您的启动器:

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));
    }
}

它看起来像很多代码,但实际上只是几个类,而且大部分连接只是为了注入新的 DummyAudioClip 实现。

哈!

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!

骄兵必败 2024-08-29 02:25:13

可能应该是高级用户。
您可以使用脉冲音频来控制应用程序声音(假设您尚未禁用它)
它应该符合合理的偏好。
右键单击音量小程序并打开首选项,然后单击应用程序选项卡。

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.

新人笑 2024-08-29 02:25:13

我想知道自定义本地安全策略是否能够阻止小程序访问音频?
我没有调查太多(谷歌搜索了术语java applet本地策略

http://www.wutka.com/hackingjava/ch3.htm#CreatingaCustomizedSecurityManager

如果加载音频文件或运行音频代码失败,小程序可能会退出并出现异常,但这可能是值得的一枪。

另一个短页
http://www.jensign.com/JavaScience/www/policyfiles/

I am wondering if a custom local security policy be able to stop the applet from accessing audio?
I didn't investigate it far (Googled the terms java applet local policy)

http://www.wutka.com/hackingjava/ch3.htm#CreatingaCustomizedSecurityManager

The applet would probably exit with an exception if it fails loading the audio file or running the audio code, but it might be worth a shot.

Another short page
http://www.jensign.com/JavaScience/www/policyfiles/

心房的律动 2024-08-29 02:25:13

看来 Pulse 将各个应用程序的卷设置存储在主目录中的普通数据库 (tbd) 文件中:(~/.pulse/(guid)-stream-volumes.tdb)

来自 Synaptic“tdb-tools”的 tdbtool 命令“包可用于检查该文件的记录,但它并不意味着可以编辑,并且似乎不可能(除非对脉冲代码有深入了解的人),因为所有值都是十六进制格式并且是不容易阅读或理解。

It appears that Pulse stores the volume settings for individual applications in a Trivial Database (tbd) file in your home directory:(~/.pulse/(guid)-stream-volumes.tdb)

The tdbtool command from the Synaptic "tdb-tools" package can be used to inspect the records of this file, but it is not meant to be edited and appears to not be possible (except by someone with intimate knowledge of the pulse code) because all of the values are in hex format and are not easily readable or understood.

云淡月浅 2024-08-29 02:25:13

我从来没有遇到过像你这样的问题,但我完全删除了pulseaudio,从那以后再也没有遇到过任何抱怨。如果您想沿着这条路走下去,这里有关于用 alsa 安全替换pulseaudio 的说明。

  1. sudo apt-get 清除pulseaudio gstreamer0.10-pulseaudio
  2. sudo apt-get autoremove
  3. sudo apt-get install alsa-base alsa-tools alsa-tools-gui alsa-utils alsa-oss linux-sound-base alsamixergui
  4. sudo apt-get install esound esound-clients esound-common libesd-alsa0 gnome-alsamixer
  5. 重新启动计算机!
  6. gstreamer-properties ----将 ALSA 设置为默认值

现在,您始终可以使用 alsamixergui 来管理所有应用程序的声音。

希望能解决您的问题。

I never encountered a problem like yours, but I removed pulseaudio completely and have never had any compaints since. In case, you want to go down that path, here are instructions for safely replacing pulseaudio with alsa.

  1. sudo apt-get purge pulseaudio gstreamer0.10-pulseaudio
  2. sudo apt-get autoremove
  3. sudo apt-get install alsa-base alsa-tools alsa-tools-gui alsa-utils alsa-oss linux-sound-base alsamixergui
  4. sudo apt-get install esound esound-clients esound-common libesd-alsa0 gnome-alsamixer
  5. Restart your computer!
  6. gstreamer-properties ----set ALSA to default

Now, you can always use alsamixergui to manage sound for all apps.

Hope that solves your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文