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 8048335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:23:58+00:00 2026-06-05T06:23:58+00:00

My media player for some reason completes while it is paused. Now i have

  • 0

My media player for some reason completes while it is paused. Now i have seen another post that said about it being async and 300ms difference and that I understand. But my main problem is that i have 20 seconds left on the video and while paused it finishes after the 20 seconds run out.
here is the relevant code that I might have messed up on:

    private void initPlayer()
{
    try {
        if(videoFile != null)
        {

            afd = getAssets().openFd(videoFile);

            instructionVideoPlayer = new MediaPlayer();

            instructionVideoPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());

            instructionVideoPlayer.setDisplay(holder);

            instructionVideoPlayer.prepare();
            Log.i("Instruction Video", "videoPrepared");
            instructionVideoPlayer.setOnCompletionListener(instructionVideoComplete);
            instructionVideoPlayer.setOnPreparedListener(this);
        }

    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        Log.i(this.toString(), "IOEXception");
        e.printStackTrace();
        //initPlayer();
    } catch (Exception e)
    {
        Log.i("InitPlayer", e.getClass().toString());
        e.printStackTrace();
    }

    restoreOverlayState();
}

The listeners:

    MediaPlayer.OnCompletionListener instructionVideoComplete = new MediaPlayer.OnCompletionListener() {

    public void onCompletion(MediaPlayer arg0) {
        Log.i("onCompletion", "called");
        if(!videoFile.contentEquals(LangSelect.INSTRUCTION_05))
        {
            Intent returnIntent = new Intent();
            returnIntent.putExtra(LangSelect.ACTION, LangSelect.GO_VIDEO_NEXT);
            setResult(RESULT_OK, returnIntent);
            continuePlaying = true;
            toFinish();

        }
        else
            toFinish();
    }
};

public void onPrepared(MediaPlayer mediaPlayer) 
{
    playVideo();
}

the play and pause functions

    private void playVideo()
{
    instructionVideoPlayer.seekTo(pausedAt);
    instructionVideoPlayer.start();
    restoreOverlayState();
}
private void pauseVideo()
{
    pausedAt = instructionVideoPlayer.getCurrentPosition();
    instructionVideoPlayer.pause();
}

private void restoreOverlayState()
{
    prefs = getSharedPreferences(SAVE_PREFS, Context.MODE_PRIVATE);

    if(prefs.getBoolean(IS_PAUSED, false))
    {
        pauseOverlay.setVisibility(View.VISIBLE);
        pauseVideo();
    }
    else
    {
        pauseOverlay.setVisibility(View.GONE);
    }
}

Edit: this only happens on the Nexus S (2.3.3) one of the phones I am testing on. The other Galaxy S(Froyo) does not have this error.

  • 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-05T06:23:59+00:00Added an answer on June 5, 2026 at 6:23 am

    I figured out what I was doing Wrong. the OnCompletionListener was being called. The problem was I was running 2 media players and setting the same onCompletionlistener to them accidentally as I was calling initPlayer twice. Once in surfaceCreated and again at the end of onResume(). Either the Galaxy S is messed up or it has weird error checking becasue this problem didnt show up there.

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

Sidebar

Related Questions

I'm creating a media player (mostly video but with some graphical interfaces) that has
I have a windows media player COM in my Windows Form project that plays
I working on a distributed mediaplayer that uses the windows media player component. Now
I got some javascript functions that control a media player object (like volumeUp(), play(),
I have a media player app that is playing music with MPMoviePlayerController. I need
Background: I'm planning on using the JW FLV Media Player for streaming some videos:
I'm working on programming a basic media player, and I'm having some trouble writing
I'm using Windows Media Player in a web page. I have version 11 installed
i have windows media player in my application.i want to allow only the supported
Hey, making a media player and need to know something. I have a menu

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.