Mute MediaPlayer 'ONLY' when a call comes in

0

I have an Activity that allows me to play and stop a MediaPlayer object, as it appears in the code, for me it is convenient that when the activity goes to the background or pause allows the MediaPlayer to continue playing (as it happens with the code that I have implemented), peeeero, it is essential that the playback stops when a call comes in, "it should only be stopped when a cell phone call comes in."

I already tried to overwrite the onPause () and onResume () method, however I do not know if there is any listener to know if a call comes in, or some event that I can overwrite.

I appreciate any contribution or clue ...

thank you very much!

package com.example.especialista.reproductor;

import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    Button btn;
    MediaPlayer mp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn=(Button)findViewById(R.id.btnPlay);
        MediaPlayer mp;
        crearReproductor();
    }


    public void onClickBtnPlay(View view) {

           mp.start();
        Toast.makeText(this, "play", Toast.LENGTH_SHORT).show();

    }

    public void onClickBtnStop(View view) {

         mp.stop();
         mp.release();
         crearReproductor();
        Toast.makeText(this, "Stop", Toast.LENGTH_SHORT).show();


    }

    public  void crearReproductor(){
        mp=MediaPlayer.create(this, R.raw.piano3);

    }
}
    
asked by John Quintero 27.04.2018 в 21:29
source

0 answers