How to resume the mediaplayer?

后端 未结 6 1984
不知归路
不知归路 2020-12-01 02:17

I am using a media player.

I have the option for starting ,stopping and pausing the player. The problem I have is that I cannot find the option to resume the song fr

6条回答
  •  悲哀的现实
    2020-12-01 02:58

    in case you use two Buttons one for play and one for pause then the below code is working and tried:

                    playbtn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPlayer = MediaPlayer.create(MainActivity.this,         
                        R.raw.adhan);
    
                        if (mPlayer.isPlaying()) {
    
    
                        } else {
                            mPlayer.seekTo(length);
                            mPlayer.start();
                          }
    
                    }
                    });
    
                   pausebtn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
    
                        mPlayer.pause();
                        length = mPlayer.getCurrentPosition();
    
    
                      }
                    });
    

提交回复
热议问题