Android Developer
Android Developer

Reputation: 9643

How to detect when video has stopped playing and perform action thereafter(Android)

In my program when user clicks on imagepreview video starts running.Video is played in same actvity in which images are.When video is played images are made invisible.I want that when video stop it should disappear and images should be visible.I tried using isPlaying() method but doesn't work out as expected.If I put isPlaying() method inside onClick() then the action inside isPlaying() is performed even before the video is started and if i place it ouside setOnClickListener() then this method doesn't execute when video is stopped.Plzz help me with code

 imgPreview.setOnClickListener(new View.OnClickListener() { //clicking on first imageView

                @Override
                public void onClick(View v) {
                    imgPreview.setVisibility(View.GONE);
                    imgPreview2.setVisibility(View.GONE);
                    videoPreview2.setVisibility(View.VISIBLE); 


                    videoPreview2.setVideoPath(fileUri.getPath());

                    videoPreview2.start();


                }

 });


if(videoPreview2.isPlaying()==false){
                imgPreview.setVisibility(View.VISIBLE);
                imgPreview2.setVisibility(View.VISIBLE);
                videoPreview2.setVisibility(View.GONE); 
            }

Upvotes: 0

Views: 956

Answers (1)

Illegal Argument
Illegal Argument

Reputation: 10338

Have you tried videoview's setcompletion listener. See the docs.

videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
    //make image visible here
}
});

Upvotes: 1

Related Questions