How to mute and unmute it on the onPause and onResume

前端 未结 1 505
Happy的楠姐
Happy的楠姐 2020-12-21 12:36

I\'m having a problem when I set the audio to Mute on the onPause() and in the onResume() I try to unmute it but without success.

Code:

1条回答
  •  别那么骄傲
    2020-12-21 13:01

    MediaPlayer ourSong;
    int length; // To save the last seconds where the music has paused
    

    In your OnCreate

    ourSong = MediaPlayer.create(yourActivity.this, YourSong);
            ourSong.setLooping(true);
    ourSong.start();
    

    In you pause function

    ourSong.pause();
    length = ourSong.getCurrentPosition();
    

    In you resume function

    ourSong.seekTo(length);
    ourSong.start();
    

    Note:

    you should make a folder row and then YourSong has to be like this R.raw.yoursong

    0 讨论(0)
提交回复
热议问题