Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 views
in Technique[技术] by (71.8m points)

android - setStreamMute never unmutes

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...