Domanda

I basically have an audio application that will be playing some music. I want to be able to pause/stop/mute the music when there is an interrupt.

These interrupts include: GPS directions, Phone Call, GPS, etc. (if there are more audio interupts, please let me know)

I already implemented the phone call interrupt, stops the music when phone call received and plays after phone call ends.

How would I do the other interrupts?

EDIT: I noticed that Android's Play Music application does this. But I am unable to find the source code of that, not sure if that would be helpful.

È stato utile?

Soluzione

Make sure you correctly ask for and release Audio Focus as described here:

http://developer.android.com/training/managing-audio/audio-focus.html

With multiple apps potentially playing audio it's important to think about how they should interact. To avoid every music app playing at the same time, Android uses audio focus to moderate audio playback—only apps that hold the audio focus should play audio.

Basically this allows the framework to handle interrupts properly as you cannot specifically code for every situation.

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