gpt4 book ai didi

android - setStreamMute 从不取消静音

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:49:43 27 4
gpt4 key购买 nike

文档中说:

The mute command is protected against client process death: if a process with an active mute request on a stream dies, this stream will be unmuted automatically.

The mute requests for a given stream are cumulative: the AudioManager can receive several mute requests from one or more clients and the stream will be unmuted only when the same number of unmute requests are received.

嗯,第一段是真的;每当我的进程终止时,我静音的所有流都会自动取消静音。但是,无论我调用 setStreamMute(someStream, false) 多少次,它都永远不会取消静音。上次我在仅静音一次后尝试调用它超过 100 万次,但没有任何反应!

只需提及 - 如果我以相同的方法将其取消静音,我将其静音 - 它会保持未静音状态。但在下次调用同一方法时 - 它永远不会取消静音。

我在广播接收器 onReceive 方法中静音,我开始使用警报管理器。所以也许是因为我的应用程序在静音调用和取消静音调用之间的时间内被杀死了? (但我的应用程序仍然留在 RAM 中)

这个问题会不会是因为我没有保留对 AlarmManager 的引用(每次都获取不同的实例?)

有人遇到过这个问题吗?

最佳答案

显然,这些 Android 版本存在错误;测试版本 2.2 和 2.3.3 并且存在错误。看起来,如果您在 AudioManager 对象上调用 setStreamMute:

AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
am.setStreamMute(...., true);

并且您丢失您的引用,然后获得引用:

am = null;
am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);

无论您现在多少次调用am.setStreamMute(..., false),它都永远不会取消静音。

我想我现在报告这个错误..

类(class):保持对 AudioManager 的静态引用。

@Michell Bak,感谢你给我想法来检查它是否是 Android 软件错误 :) 我已经在这件事上停留了太多时间,而且我从来没有想过看看这是否不是我的错.

关于android - setStreamMute 从不取消静音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7908962/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com