Home » Java » java – how to set image preview on videoView before playing the video?-Exceptionshub

java – how to set image preview on videoView before playing the video?-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am trying to set a preview image of my video before playing. I am using seekTo( ) to perform the task.
But when the Activity starts the background of the Video View is black but after some second maybe 5, the background turns to white without the image from the video.

The below code is placed oncreate(), I want the seekTo() to be called after the video’s link is fetched

     FirebaseDatabase.getInstance().getReference().child("videoAd")
            .addChildEventListener(new ChildEventListener() {
                @Override
                public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

                    try {
                    Downloaduri = (String) dataSnapshot.child("VideoLink").getValue();
                    vView.setVideoURI(Uri.parse(Downloaduri));
                    vView.pause();
                    vView.seekTo(1);

                         }catch (Exception e){
                   Toast.makeText(Lengo1.this, e.getMessage(),Toast.LENGTH_LONG).show();
                                             }
                     }    

Below is the method for playing the video after fetching it.

   private void playingVideo(){

    try {
        vView.setMediaController(mController);
        mController.show();
        vView.pause();
        vView.stopPlayback();
        vView.resume();
        vView.requestFocus();
        vView.start();
        playBtn.setVisibility(View.GONE);

    }catch (Exception e){
        Toast.makeText(Lengo1.this, e.getMessage(), Toast.LENGTH_LONG).show();
    }
}

I don’t know what is going wrong that makes the video view preview white without showing the image from the video, even after wait for long enough.

How to&Answers: