How to resume the mediaplayer?

后端 未结 6 1975
不知归路
不知归路 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:35

       public class MainActivity extends AppCompatActivity {
    
        MediaPlayer mediaPlayer;
       public void play(View view) {
               mediaPlayer.start();
       }
       public void pause(View view){
               mediaPlayer.pause();
       }
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mediaPlayer= MediaPlayer.create(this,R.raw.someaudio);
        }
    }
    

    Make two buttons for play and pause. And use this code. It worked for me.

提交回复
热议问题