android - How to pause music when phone rings, sms is received, etc? -


i'm trying detect android sounds , pause app's music (temporarily or permanently) while make noise.

this code appears nothing (stop pauses music , p writes log), never gets called:

public class pollyprissypants extends activity implements onaudiofocuschangelistener {     // blah blah blah     public void onaudiofocuschange(int mal) {         p("--change!!!--" + mal);         stop();     }     // yada yada yada } 

do have set somewhere else well? @override relevant?

i haven't tried phonestatelistener if possible don't want have treat phone calls, alarms, notifications, games, etc separately. i'm using vibrate sucks solution. if called, have answer , app , pause it.

you have register onaudiofocuslistener audiomanager:

audio = (audiomanager) getsystemservice(context.audio_service); audio.requestaudiofocus(this,       audiomanager.stream_music, audiomanager.audiofocus_gain); 

the this parameter reference class implementing onaudiofocuslistener.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -