Reputation: 4781
I am working on playing the live streaming using media player. I have got it worked . But when i Make a call and end the call, audio stops and resumes automatically.
But when i receive the incoming call , audio stops and does not resumed again.
I used the following code to implement. Handling Android application pause on incoming call and resume after call end . But this is not working. Below is my code. I have used the following as a service as well as in the same activity where i used the media player.
private void callsettings() {
PhoneStateListener phoneStateListener = new PhoneStateListener(){
@Override
public void onCallStateChanged(int state, String incomingNumber) {
// TODO Auto-generated method stub
super.onCallStateChanged(state, incomingNumber);
if (state == TelephonyManager.CALL_STATE_RINGING) {
mute();
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
Unmute();
} else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
mute();
}
}
};
TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if (mgr != null) {
mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
private void mute() {
am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.setStreamMute(AudioManager.STREAM_MUSIC, true);
//am.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
}
private void Unmute() {
am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
//am.setStreamVolume(AudioManager.STREAM_MUSIC, 5, 0);
am.setStreamMute(AudioManager.STREAM_MUSIC, false);
}
Please help me here, idk what is the reason for this problem . thank in advance.
Upvotes: 2
Views: 1111
Reputation: 11
Probably you can this can resolve.
you have to Audio Manager for focus: requestAudioFocus with stream type as VOICE Call. After call ends, you will get audio service focus back then you can resume.
have a look here: http://developer.android.com/training/managing-audio/audio-focus.html
Upvotes: 1