Vote count:
0
When I'm listening to my streaming app and I open another music player,like Play on Google, or YouTube, our player keeps playing together. The correct behaviour is mute the sound of my app when any other app plays sound or video.
i find a solve from another stackoverflow which is This is how I solved the issue.
Implement OnAudioFocusChangeListener listener
Initialise AudioManager
private AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
Request Audio focus
mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
Overide the following method of OnAudioFocusChangeListener
public void onAudioFocusChange(int focusChange) { switch (focusChange) { case AudioManager.AUDIOFOCUS_GAIN: case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: resumePlayer(); // Pause your media player here break; case AudioManager.AUDIOFOCUS_LOSS: case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: pausePlayer();// Pause your media player here break; } }
but this is not working, and i am not also clear is musiceservice class will implements it or my activity class, and can this add in another service?
asked 1 min ago
my music service app not mute when another music app start
Aucun commentaire:
Enregistrer un commentaire