1

i am using video player in my application. its working fine. But i need while android "HOME" button clicking video player in pause state and again i click application it continue from last played state.

here my code:

videoView = (VideoView)findViewById(R.id.videoView);
MediaController mediaController= new MediaController(this);
        mediaController.setAnchorView(videoView);  
        String path1="http://commonsware.com/misc/test2.3gp";
        Uri uri=Uri.parse(path1);
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(uri);

        videoView.requestFocus();
        videoView.start();    
@Override
    protected void onPause() {
        videoView.pause();
        super.onPause();

    }
    @Override
    protected void onResume(){
        videoView.start();
        super.onResume();

    } 

any one can help me?

2 Answers 2

5

solved this issue. here my answer

@Override
protected void onResume() {
    super.onResume();
    try{
        if (videoView != null) {
            videoView.seekTo(position);    
            videoView.start();
        }
    }catch (Exception e) {
                }
}

@Override
protected void onPause() {
    super.onPause();    
    try{
        if (videoView != null) {
            position = videoView.getCurrentPosition();
            videoView.pause();         
        }
    }catch (Exception e) {
                }
}
1
  • This solution worked for me as well but another problem arise that is Hardware back key works only when pressed twice Feb 9, 2017 at 16:14
0

Please refer android API reference for VideoView

You can use the following methods to achieve this.

int getCurrentPosition ()

and

void seekTo (int msec)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.