android - Stop a Mediaplayer that was started from another application -


how applications soundcloud stop app's mediaplayer? example, when playing song through google music , open soundcloud, song google music stops playing soundcloud song starts. might missing obvious have wondered how achieved.

thanks, justin

use audio focus. see request audio focus

audiomanager = mcontext.getsystemservice(context.audio_service); ...  // request audio focus playback int result = am.requestaudiofocus(afchangelistener,                                  // use music stream.                                  audiomanager.stream_music,                                  // request permanent focus.                                  audiomanager.audiofocus_gain);  if (result == audiomanager.audiofocus_request_granted) {     am.unregistermediabuttoneventreceiver(remotecontrolreceiver);     // start playback. } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -