Domanda

I am streaming music via an Android service. I am trying to stop-resume music when there's an incoming call. I don't have any problems stopping the music, I'm shutting down the service by calling

stopself()

method.

My question is, how can I restart the service again when the phone state is idle again from within the service after closing itself? I have to assume that the activities might not be there since the music is running in the background.

È stato utile?

Soluzione

Do not stop the service using stopSelf in this case.

Your service should implement AudioManager.OnAudioFocusChangeListener.

When your application needs to output audio such as music or a notification, you should always request audio focus. When you loose audio focus you can stop the media player or reduce the volume. You can start back or increase the volume when audio focus gain.

Read Handling audio focus in the link

http://developer.android.com/guide/topics/media/mediaplayer.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top