Actually you have to listen for incoming calls and manually pause/
resume the playback yourself.
You can find a good example of how to do that by looking at the source
of the built-In  Music Player application.
(It is part of the source for Android itself)

Here is a simplified snippet of code we use:

public class XXXPhoneStateListener extends PhoneStateListener
        {
                @Override
                public void onCallStateChanged(int state, String incomingNumber)
                {
                        if (state == TelephonyManager.CALL_STATE_RINGING)
                        {
                                AudioManager audioManager = (AudioManager) 
getSystemService
(Context.AUDIO_SERVICE);
                                int ringvolume = audioManager.getStreamVolume
(AudioManager.STREAM_RING);
                                if (ringvolume > 0)
                                {
                                   //Pause the playback
                                }
                        } else if (state == TelephonyManager.CALL_STATE_OFFHOOK)
                        {

                                //Pause playback again
                                
MediaButtonIntentReceiver.StopListeningForMediaButton();
                        } else if (state == TelephonyManager.CALL_STATE_IDLE)
                        {
                                // resume playing again
                        }
                }
        }

On May 5, 8:35 pm, Mark Murphy <[email protected]> wrote:
> iloveblue wrote:
> > While I am playing the music in background as a service. And then a
> > phone call happens, what should the service do? Will the OS (android)
> > pause the service
>
> No, there is no "pause" with services.
>
> > or will the developer who develop the service write
> > code to detect things like this and define the operations?
>
> That certainly is a possibility, perhaps using a PhoneStateListener.
>
> I have not written a music-playing service, or any form of background
> audio. It is possible that such playback is automatically muted by the
> system, via some sort of audio stream prioritization.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android App Developer Books:http://commonsware.com/books.html
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to