setStreamMute 永远不会取消静音
在文档中说:
静音命令可以防止客户端进程死亡:如果流上有活动静音请求的进程死亡,该流将自动取消静音。
给定流的静音请求是累积的:AudioManager 可以从一个或多个客户端接收多个静音请求,只有当收到相同数量的取消静音请求时,该流才会取消静音。
嗯,第一段是正确的;每当我的进程终止时,我静音的所有流都会自动取消静音。 但是,无论我调用 setStreamMute(someStream, false) 多少次,它都永远不会取消静音。 上次我尝试在静音一次后拨打超过 100 万次,但什么也没发生!
只是提一下 - 如果我以相同的方法取消静音,我将其静音 - 它保持未静音状态。但在下次调用同一方法时 - 它永远不会取消静音。
我在广播接收器的 onReceive 方法中静音,我开始使用警报管理器。那么也许是因为我的应用程序在静音呼叫和取消静音呼叫之间被终止了? (但我的应用程序仍然保留在 RAM 中)
这个问题是否是因为我没有保留对 AlarmManager 的引用(每次获取不同的实例?)
有人遇到过这个问题吗?
In the documentation, it is said:
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.
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.
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)
Can this problem be because I am not keeping a reference to the AlarmManager (Getting different instances each time?)
Did anyone encounter this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
显然,这些 Android 版本中存在一个错误;测试了 2.2 和 2.3.3 版本,存在该错误。
看起来,如果您在 AudioManager 对象上调用
setStreamMute
:并且您丢失您的引用,然后获得一个新引用:
无论现在,您调用
am.setStreamMute(..., false)
多少次,它就永远不会取消静音。我想我现在就报告这个错误。
课程:保留对 AudioManager 的静态引用。
@Michell Bak,谢谢你给了我检查是否是 Android 软件错误的想法:) 我已经在这件事上停留了太多时间,而且我从来没有想过看看这是否不是我的错。
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:and you lose your reference, then get a new reference:
No matter how many times you call
am.setStreamMute(..., false)
now, it will never unmutes.I think ill report this bug now..
Lesson: Keep a static reference to your AudioManager.
@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.
我以前从未使用过该 API,但快速 Google 搜索后,返回了一些结果,但它不起作用。这似乎是 Android 2.3 中仍然存在的一个错误:
http:// code.google.com/p/android/issues/detail?id=4235
I've never used that API before, but a quick Google search, returned a few results with it not working. It seems to be a bug that's still present in Android 2.3:
http://code.google.com/p/android/issues/detail?id=4235
我通过将音频管理器变量放入应用程序中来解决问题
然后在我的活动类中添加此函数:
以下是我如何使用 getAM();
I solve the problem by putting the audio manager variable in the application
Then in my activity class add this function:
and here is how I use the getAM();
我在使用新版本的 API 时也遇到了同样的问题。因此,为了解决这个问题,我实施了一些“老式”解决方案。如果您的设计是直接处理获取字节流/发送字节流 - 如果选择静音,则发送一个填充零的字节数组:
**
I have been having the same problem w/ newer versions of the API. So, to work [around] this issue, I've implemented a bit of 'old-school' solution. If your design is such that you handle getting the byte stream / sending the byte stream directly - send a byte array filled with zeros if mute is selected:
*
*