Playing video from the pause state in VideoView

I think the problem is that videoView.getCurrentPosition() will always return 0 when you call inside onSaveInstanceState(Bundle outState), cos at that time the video already reset, so call videoView.getCurrentPosition() when onPause(), this will return you the desired value.


I had the same problem. I thought I did everything right but it didnt work. Then I just changed the order so I first call VideoView.seekTo() and then VideoView.start() . That worked. I also have VideoView.requestFocus() in there but I dont know if that matters.

videoPlayer.requestFocus();
videoPlayer.seekTo(position);
videoPlayer.start();

So if youre sure you position variable has the right value, this might be your answer. You may not be able to seek when the Video is not loaded. Implement onPreparedListener like this:

public class VideoActivity extends Activity implements OnPreparedListener {
    VideoView videoPlayer;
    int position;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(savedInstanceState!=null){
    position=savedInstanceState.getInt("pos")
    }
    // setting up the videoview
    setContentView(R.layout.activity_video);
    getIntent().getExtras().getString("url");
    Uri videouri = Uri.parse(getIntent().getExtras().getString("url"));
    videoPlayer = (VideoView) findViewById(R.id.videoView);
    videoPlayer.setOnPreparedListener(this);
    videoPlayer.setKeepScreenOn(true);
    videoPlayer.setVideoURI(videouri);

    }

    /**
     * Start the plaback when the video is loaded
     * 
     * @param mp
     * @see android.media.MediaPlayer.OnPreparedListener#onPrepared(android.media.MediaPlayer)
     */
    public void onPrepared(MediaPlayer mp) {
    //this is a TextView infront of the VideoView which tells the User the Video is loading- hide that
    findViewById(R.id.tv_video_load).setVisibility(View.GONE);

    videoPlayer.requestFocus();
    videoPlayer.seekTo(position)
    videoPlayer.start();
}
}