Android MediaPlayer, SeekBar Exception when change activity

I am currently working on an android application with audio playing function. In the play_pause Activity, I have a seekbar and a button to control the audio.

public class PlayerActivity extend AppCompatActivity {
    public void onCreate(Bundle savedInstanceState) {
        playerButton = (Button) findViewById(;

        playerButton.setOnClickListener(new Button.setOnClickListener() {
                if (player != null) {
                     //load music to player

                     mTimer = new Timer();
                     mTimerTask = new TimerTask() {
                         public void run() {
                     mTimer.schedule(mTimerTask, 0, 10);

When I press the back button without hit the "play" button, my application can change activity successfully. However, once the "play" button has been clicked, I can not change activity. Below is the onDestroy() method.

protected void onDestroy() {

The Logcat has the error message saying

at MediaPlayer.getCurrentPosition()
at //which is the mTimerTask
at java.util.Timer$

Anyone have idea how to solve?


Cancel your Timer onDestroy of Activity too by calling


Exception raised due to call of player.getCurrentPosition(); after release of Media player instance on destroy of Activity as you timer thread dont stops.

Need Your Help

xlwt: write multiple columns

python excel xlwt

I have a file containing data like below

Bundler using an older Ruby version

ruby-on-rails ruby bundler

I have Ruby 2.3.0 installed in my system. The output of ruby -v is: