Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : how to know if MediaPlayer is paused?

MediaPlayer.isPlaying() does not allow to know if the MediaPlayer is stopped or paused. How to know if it is paused and not stopped?

Thanks !

like image 802
Regis_AG Avatar asked Mar 04 '14 09:03

Regis_AG


2 Answers

One way to do this is to check if the media player it not playing (paused) and check if it is at a position other than the starting position (1).

MediaPlayer mediaPlayer = new MediaPlayer();

Boolean isPaused = !mediaPlayer.isPlaying() && mediaPlayer.getCurrentPosition() > 1;
like image 154
rickdmer Avatar answered Oct 06 '22 00:10

rickdmer


There is no API to check if MediaPlayer is paused or not. So please use any Boolean variable to check and toggle it when you paused using any button.

onClick(){
 if(isPaused)
  {
    //resume media player
    isPaused = false;
  }else{
   // pause it
     isPaused = true;
  }
} 
like image 31
Ankit Avatar answered Oct 06 '22 00:10

Ankit