setStreamMute从来没有取消静音从来没有、静音、setStreamMute

2023-09-13 01:11:14 作者:在眼泪中学会了坚强

在文档中,它是说:

静音命令进行保护,防止客户端进程死亡:如果有一个流上的主动静音请求的进程死亡,这个流会自动静音。

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.

有一个给定的流中的静音请求是累积:所述AudioManager可以从一个或多个客户接收若干静音请求和接收取消静音请求相同数量的,只有当流将被取消静音。

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万次!

Well, the first paragraph is true; Whenever my process dies, all of the streams I muted are automatically unmuted. However, no matter how many time I call setStreamMute(someStream, false) it NEVER EVER unmutes. Last time I tried calling it over 1 million times after muting only ONCE and NOTHING happens!

刚提 - 如果我静音它在相同的方法,我静音它 - 它保持静音。但在下次调用相同的方法 - 它从未取消静音

Just to mention - If i unmute it in the same method I mute it - it stays unmuted. But on the next calls to the same method - it never unmutes.

我静音的广播接收器的onReceive方法,我开始使用报警管理。因此,也许是因为我的应用程序是在静音通话和取消静音通话之间的时间杀? (但是,我的应用还停留在RAM)

I am muting in a Broadcast Receiver onReceive method, which I start using an alarm manager. So maybe it because my app was killed during the time between the muting call and the unmuting call? (But my app still stays in the RAM)

可这个问题是因为我没有保持引用AlarmManager(每次获得不同的实例?)

Can this problem be because I am not keeping a reference to the AlarmManager (Getting different instances each time?)

有没有人遇到这样的问题?

Did anyone encounter this problem?

推荐答案

Apperantly,有是在这些安卓版本的bug;测试的版本2.2和2.3.3和存在错误。 看起来,如果调用 setStreamMute 的AudioManager对象:

Apperantly, there is a bug in these Android versions; Tested for versions 2.2 and 2.3.3 and the bug exists. Looks like, if you call setStreamMute on an AudioManager object:

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

和您的失去您参考,然后得到一个新参考:

and you lose your reference, then get a new reference:

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

无论如何很多你叫次 am.setStreamMute(...,FALSE)现在,它将永远取消静音。

No matter how many times you call am.setStreamMute(..., false) now, it will never unmutes.

我觉得不适的报告,现在这个bug。

I think ill report this bug now..

教训:保持静态引用您的AudioManager

Lesson: Keep a static reference to your AudioManager.

@Michell朴,感谢给我的主意,检查其是否在Android软件中的bug :)我一直停留在这个事情了太多的时间,我从未有过的想法,如果它不是我的错,看看

@Michell Bak, thanks for giving me the idea to check whether its the Android software bug :) I've been stuck on this thing for way too much time, and I never had the idea to see if its not my fault.