Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8219101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:02:41+00:00 2026-06-07T13:02:41+00:00

Why i am getting illegalstate exception when the song is over? I am getting

  • 0

Why i am getting illegalstate exception when the song is over? I am getting this error at seekcontrol.setProgress(mediaPlayer.getCurrentPosition());. Is there any thing to do with the seekbar or this is because of something else?

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.media3);

    Intent i1 = getIntent();
    kg1 = i1.getStringExtra("Kggg1");
    MixName1 = i1.getStringExtra("mixname1");
    MixReplace=MixName1.replace(".mp3", "  ");
    initViews();
}
private void initViews() {
    mediaPlayer = new MediaPlayer();
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    txtcrnt = (TextView) findViewById(R.id.txtcurnt);
    txtremain = (TextView) findViewById(R.id.txtremain);
    txtcrntbig = (TextView) findViewById(R.id.txtcrntbig);
    txttitle=(TextView) findViewById(R.id.title);
    btnpre = (ImageButton) findViewById(R.id.btnpre);
    btnnext = (ImageButton) findViewById(R.id.btnnext);
    btnplay = (ImageButton) findViewById(R.id.btnplay);
    btnrepeat=(ImageButton) findViewById(R.id.btnrepeat);
    btnback = (Button) findViewById(R.id.btnlout);
    btnplayer = (Button) findViewById(R.id.btnedit);
    btnback.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ((MyMixes)getParent()).goBack();
        }
    });

    btnplayer.setClickable(true);
    btnplayer.setEnabled(false);
    btnplayer.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

        }
    });

    seekcontrol=(SeekBar) findViewById(R.id.seekbarcontrol);

    seekcontrol.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            if(fromUser){
                mediaPlayer.seekTo(progress);
                seekcontrol.setProgress(progress);
            }

        }
    });


    btnplay.setOnClickListener(new OnClickListener() {

        public void onClick(View paramView) {

            btnClick();
        }
    });

    btnplay.setOnClickListener(new OnClickListener() {

        public void onClick(View paramView) {
            if (mediaPlayer != null && mediaPlayer.isPlaying()) {
                if (mediaPlayer != null) {
                    mediaPlayer.pause();
                    btnplay.setImageResource(R.drawable.play);
                }
            } else {
                if (mediaPlayer != null && mediaPlayer != null) {
                    mediaPlayer.start();
                    startPlayProgressUpdater();
                    btnplay.setImageResource(R.drawable.pause);
                }
            }
        }
    });

    btnnext.setOnClickListener(new OnClickListener() {

        public void onClick(View paramView) {

        }
    });

    btnpre.setOnClickListener(new OnClickListener() {

        public void onClick(View paramView) {



        }
    });

    seekvolume = (SeekBar) findViewById(R.id.seekbarvolume);

    new Thread()
    {
        public void run() 
        {
            while (isDownloading)
            {
                if (Data.filenames != null&& Data.filenames.size() >= (getIntent().getExtras().getInt("index") + 1) && Data.filenames.get(getIntent().getExtras().getInt("index")) != null) 
                {
                    try 
                    {
                        mediaPlayer.setDataSource(Data.filenames.get(getIntent().getExtras().getInt("index")));
                        mediaPlayer.prepare();
                        mediaPlayer.start();
                        startPlayProgressUpdater();
                        mediaPlayer.setOnCompletionListener(new OnCompletionListener() 
                        {
                            @Override
                            public void onCompletion(MediaPlayer mp) 
                            {
                                mediaPlayer.stop();
                                mediaPlayer.release();
                            }
                        });
                    } catch (IllegalArgumentException e) {
                        e.printStackTrace();
                    } catch (IllegalStateException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        isDownloading = false;
                    }

                    if (mediaPlayer != null)
                        seekcontrol.setMax(mediaPlayer.getDuration());

                    int maxvolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
                    int curntvolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);

                    seekvolume.setMax(maxvolume);
                    seekvolume.setProgress(curntvolume);

                    seekvolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() 
                    {

                        public void onStopTrackingTouch(SeekBar paramSeekBar) {
                        }

                        public void onStartTrackingTouch(SeekBar paramSeekBar) {
                        }

                        public void onProgressChanged(SeekBar paramSeekBar, int progress, boolean paramBoolean) 
                        {
                            audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
                        }
                    });
                    seekcontrol.setMax(mediaPlayer.getDuration());

                    seekcontrol.setOnTouchListener(new OnTouchListener() 
                    {
                        public boolean onTouch(View v, MotionEvent paramMotionEvent) 
                        {
                            seekChange(v);
                            return false;
                        }
                    });
                }
            }
        };
    }.start();
}

protected void btnClick() {
    i++;
    i = i % 2;
    startSong(i);
}
 private void startSong(int i) {
        if (i == 1) {
            System.out.println("11111" + i);
            btnplay.setBackgroundResource(R.drawable.pause);
            try {
                System.out.println("start try chech------");
                mediaPlayer.start();
                startPlayProgressUpdater();
            } catch (Exception e) {
                mediaPlayer.pause();
            }
        }
        if (i == 0) {
            btnplay.setBackgroundResource(R.drawable.play);
            mediaPlayer.pause();
            System.out.println("00000" + i);
        }
    }

public void startPlayProgressUpdater() {

    Log.e("position", mediaPlayer.getCurrentPosition()+"");
    seekcontrol.setProgress(mediaPlayer.getCurrentPosition());

    if (mediaPlayer.isPlaying()) {
        Runnable notification = new Runnable() {
            public void run() {
                startPlayProgressUpdater();

                int curtimeplay = mediaPlayer.getCurrentPosition();
                int curntseconds = (int) (curtimeplay / 1000) % 60;
                int curntminutes = (int) ((curtimeplay / (1000 * 60)) % 60);
                txtcrnt.setText(curntminutes + ":" + curntseconds);
                txtcrntbig.setText(curntminutes + ":" + curntseconds);

                int duratplay = mediaPlayer.getDuration();
                int totaldurationseconds = (int) (duratplay / 1000) % 60;
                int totaldurationminutes = (int) ((duratplay / (1000 * 60)) % 60);
                int remianingtime = duratplay - curtimeplay;
                int remianingtimeseconds = (int) (remianingtime / 1000) % 60;
                int remianingtimeminutes = (int) ((remianingtime / (1000 * 60)) % 60);
                txtremain.setText(remianingtimeminutes + ":"
                        + remianingtimeseconds);
            }
        };
        handler.postDelayed(notification, 1000);
    } else {
        mediaPlayer.pause();

        btnplay.setBackgroundResource(R.drawable.play);

        seekcontrol.setProgress(mediaPlayer.getCurrentPosition());
    }

}

 protected void seekChange(View v) {
        if (mediaPlayer.isPlaying()) {
            SeekBar sb = (SeekBar) v;
            mediaPlayer.seekTo(sb.getProgress());
        }
    }

Logcat

07-14 21:45:31.530: E/AndroidRuntime(13870): FATAL EXCEPTION: main
07-14 21:45:31.530: E/AndroidRuntime(13870): java.lang.IllegalStateException
07-14 21:45:31.530: E/AndroidRuntime(13870):    at android.media.MediaPlayer.getCurrentPosition(Native Method)
07-14 21:45:31.530: E/AndroidRuntime(13870):    at com.nelitemusic.MediaPlay1.startPlayProgressUpdater(MediaPlay1.java:253)
07-14 21:45:31.530: E/AndroidRuntime(13870):    at com.nelitemusic.MediaPlay1$9.run(MediaPlay1.java:259)
07-14 21:45:31.530: E/AndroidRuntime(13870):    at android.os.Handler.handleCallback(Handler.java:587)
07-14 21:45:31.530: E/AndroidRuntime(13870):    at android.os.Handler.dispatchMessage(Handler.java:92)
07-14 21:45:31.530: E/AndroidRuntime(13870):    at android.os.Looper.loop(Looper.java:132)
07-14 21:45:31.530: E/AndroidRuntime(13870):    at android.app.ActivityThread.main(ActivityThread.java:4126)
07-14 21:45:31.530: E/AndroidRuntime(13870):    at java.lang.reflect.Method.invokeNative(Native Method)
07-14 21:45:31.530: E/AndroidRuntime(13870):    at java.lang.reflect.Method.invoke(Method.java:491)
07-14 21:45:31.530: E/AndroidRuntime(13870):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
07-14 21:45:31.530: E/AndroidRuntime(13870):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
07-14 21:45:31.530: E/AndroidRuntime(13870):    at dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:02:45+00:00Added an answer on June 7, 2026 at 1:02 pm
    seekcontrol.setProgress(mediaPlayer.getCurrentPosition());
    

    is called inside startPlayProgressUpdater(), that is called inside the inner thread. Since SeekBar can be touched only by the UI Thread, you should use an Handler to post the

    seekcontrol.setProgress(mediaPlayer.getCurrentPosition());
    

    into the UI Thread queue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I keep getting this error : 07-27 17:13:13.817: INFO/My Music Test(11215): Initializing: Song
Getting this error: 2009-09-03 12:44:02.307 xcodebuild[307:10b] warning: compiler 'com.apple.compilers.llvm.clang.1_0.analyzer' is based on missing compiler
Getting a rendering error for this form: 'NoneType' object has no attribute 'widget' http://dpaste.com/88585/
Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded to
I'm getting this exception: Exception: java.lang.IllegalStateException: Can't copy a recycled bitmap My code is:
So, I'm getting this error 11-15 16:55:40.617: E/AndroidRuntime(316): java.lang.IllegalStateException: Could not find a method
I m getting exception as follow. Can anybody help me? 06-16 11:32:48.237: ERROR/AndroidRuntime(9223): java.lang.IllegalStateException:
I seem to be getting this error... I believe I am typing everything correctly:
my code works fine but I am getting this exception a lot and it's
I am getting this exception in database Leak Found my LOGCAT Shows this: 02-17

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.