Esempio n. 1
0
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {

          super.onCallStateChanged(state, incomingNumber);
          Log.d("radio", " Got something with the phone : " + state);

          if (state != TelephonyManager.CALL_STATE_IDLE) {

            if (mediaPlayer.isPlaying()) {

              mediaPlayer.stop();
              try {
                mediaPlayer.prepareAsync();
              } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
              wasPlaying = true;
            }
          } else if (wasPlaying) {

            mediaPlayer.start();
            wasPlaying = false;
          }
        }
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
          if (state == TelephonyManager.CALL_STATE_RINGING) {

            /** Stop radio and set interrupted if it is playing on incoming call. */
            if (isPlaying()) {
              isInterrupted = true;
              stop();
            }

          } else if (state == TelephonyManager.CALL_STATE_IDLE) {

            /** Keep playing if it is interrupted. */
            if (isInterrupted) play(mRadioUrl);

          } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {

            /** Stop radio and set interrupted if it is playing on outgoing call. */
            if (isPlaying()) {
              isInterrupted = true;
              stop();
            }
          }
          super.onCallStateChanged(state, incomingNumber);
        }