Does AudioManager send message to dead thread handler?

I am trying to programmatically increase the volume to the maximum value of the STREAM_MUSIC stream, but I have the message "Sending a message to the processor on a dead stream" when I do this. In addition, it does not seem to raise the volume 100% of the time, although when I get this error, it will raise it at the same time.

The code:

 System.out.println("Maximum volume for this stream is: "+maxstreamvol+" and it used to be set to: "+currentvol); final AudioManager am = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE); am.setStreamVolume(AudioManager.STREAM_MUSIC, maxstreamvol, AudioManager.FLAG_SHOW_UI); am.setStreamSolo(AudioManager.STREAM_MUSIC, true); System.out.println("Volume Raised!"); 

After a google search, it seems that this error is due to multithreaded situations ... The code at this point should work in the user interface thread.

In fact, I even surrounded him:

 runOnUiThread(new Runnable() { public void run() { // code_goes_here } }); 

And it caused the same error. The error I see is this:

 I/System.out(24949): Maximum volume for this stream is: 15 and it used to be set to: 0 W/MessageQueue( 490): Handler (android.media.AudioManager$FocusEventHandlerDelegate$1) {42b52f28} sending message to a Handler on a dead thread W/MessageQueue( 490): java.lang.RuntimeException: Handler (android.media.AudioManager$FocusEventHandlerDelegate$1) {42b52f28} sending message to a Handler on a dead thread W/MessageQueue( 490): at android.os.MessageQueue.enqueueMessage(MessageQueue.java:294) W/MessageQueue( 490): at android.os.Handler.enqueueMessage(Handler.java:618) W/MessageQueue( 490): at android.os.Handler.sendMessageAtTime(Handler.java:587) W/MessageQueue( 490): at android.os.Handler.sendMessageDelayed(Handler.java:558) W/MessageQueue( 490): at android.os.Handler.sendMessage(Handler.java:495) W/MessageQueue( 490): at android.media.AudioManager$1.dispatchAudioFocusChange(AudioManager.java:1894) W/MessageQueue( 490): at android.media.IAudioFocusDispatcher$Stub.onTransact(IAudioFocusDispatcher.java:57) W/MessageQueue( 490): at android.os.Binder.execTransact(Binder.java:351) W/MessageQueue( 490): at dalvik.system.NativeStart.run(Native Method) I/System.out(24949): Volume Raised! 

Does anyone know what is going on here?

+6
source share
2 answers

Your problem may be related to reporting this thread - onPostExecute is not called in AsyncTask (exception handler environment)

The display for changing the focal length triggers a user interface event that the android cannot execute. It is not immediately clear why this is so. Perhaps the audio manager was obtained with one context, and a toast to show that the volume is running in a different context? A quick and dirty change is to replace the flag for FLAG_VIBRATE and verify that it matters. This narrowed the problem down to updating a user interface that you can work with.

+3
source

AudioManager uses the stream that was created to call your callback or manipulate the user interface (displaying toast toasts, etc.)
(Via Looper.myLooper or getMainLooper , see this ).

So, you have to make sure that your first call to Context.getSystemService(AUDIO_MANAGER) occurs in the user interface thread.
(Not sure if calls with subsequences will reuse this instance, but even if I get AudioManager again, an exception still occurs)

Today I ran into this problem and solved it by adding this call to my Application.onCreate (). (Rather like this answer?)

0
source

All Articles