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

  • Home
  • SEARCH
  • 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 8560539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:17:55+00:00 2026-06-11T16:17:55+00:00

I am using a MediaPlayer in my Activity . When I hit the back

  • 0

I am using a MediaPlayer in my Activity.

When I hit the back button, I get this error:

09-20 19:44:16.540: E/MediaPlayer(1822): pause called in state 64
09-20 19:44:16.540: E/MediaPlayer(1822): error (-38, 0)

Code

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        if (mp!= null && mp.isPlaying()) {
            mp.stop(); 
        }

        Intent intentstart = new Intent(X.this, Y.class);
        intentstart.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intentstart);
    }

    return super.onKeyDown(keyCode, event);
}

If I use mp.pause(), it’s working fine. Why?

  • 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-11T16:17:56+00:00Added an answer on June 11, 2026 at 4:17 pm

    It’s illegal to pause a stopped MediaPlayer, and according to that error message that sounds exactly like what you’re doing.

    I suggest changing your onPause such that it does not try to pause the stopped MediaPlayer.

    Perhaps:

        if(mp!= null) {
           if(mp.isPlaying()) mp.pause();
        }
    

    Actually don’t do this, I just found this in the docs:

    Note that the transition from the Started state to the Paused state and vice versa happens asynchronously in the player engine. It may take some time before the state is updated in calls to isPlaying(),

    You should maintain a variable locally to check if you’ve already stopped the MediaPlayer, and then test that for whether or not you should call pause().

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

Sidebar

Related Questions

I made an WPF app that plays sounds using the MediaPlayer class. This works
I've got a MediaPlayer inside an activity which is called whenever a user clicks
Hey, I'm using MediaPlayer to play a regular ShoutCast stream. The code is straightforward
I'm using MediaPlayer on Honeycomb and cannot get the duration of any HLS (http
I am having some trouble using the android MediaPlayer in a non activity class,
In XNA I'm using MediaPlayer to play my music. I found that when playing
I am developing a simple calculator for a device, there I am using mediaplayer
At the beginning of a level in my XNA based game, I'm using MediaPlayer.Play()
I'm using the MediaPlayer to stream MP3 files via http and it works great
I am trying to play continuous stream using android mediaplayer.but am not able to

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.