2

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.

Community
  • 1
  • 1
Swaminathan V
  • 4,663
  • 2
  • 22
  • 32
  • You have to store the seek time of video while activity is moving out of user screen and the saved seek time will be use to restore the last state of video. – Roll no1 Dec 30 '14 at 08:53
  • Thanks for quick comment Roll. But i am using the audio live streaming and i think its hard to fetch the seek time. – Swaminathan V Dec 30 '14 at 09:29
  • Can you share code snipet. I think this state diagram will help you : http://developer.android.com/reference/android/media/MediaPlayer.html – Roll no1 Dec 30 '14 at 09:34

1 Answers1

1

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

Sharan
  • 11
  • 2
  • What the OP is interested in is `OnAudioFocusChangeListener`, which is included in @Sharan 's answer – nstosic Jan 23 '15 at 11:59