How to set the preview image in videoview before playing How to set the preview image in videoview before playing android android

How to set the preview image in videoview before playing


Use seekTo( 1 ) to show the first frame.

Ensure the movie is paused and then use seekTo() to show the first frame of the video:

VideoView mVideoView = (VideoView) findViewById( R.id.video_preview );mVideoView.setVideoURI( yourVideoPath );mVideoView.seekTo( 1 );                 // 1 millisecond (0.001 s) into the clip.

NOTE: We use .seekTo( 1 ) because setting .seekTo( 0 ) did not work on Android 9.

To have it play when clicked on has been answered by @Lingviston in another answer.


Create video thumbnail using this

Bitmap thumb = ThumbnailUtils.createVideoThumbnail("file path/url",                            MediaStore.Images.Thumbnails.MINI_KIND);

and set to videoview

BitmapDrawable bitmapDrawable = new BitmapDrawable(thumb);            mVideoView.setBackgroundDrawable(bitmapDrawable);


1) Remove your onPrepareListener. I don't know why your video is starting playing after activity creation but onPrepareListener is called after videoView.start().

2) Add an ImageView widget into you layout on top of VideoView. Then set another onPrepareListener like this:

vvVideos.setOnPreparedListener(new OnPreparedListener() {            public void onPrepared(MediaPlayer mp) {                previewImage.setVisibility(View.GONE);            }        });

I've noticed that onPreparedListener fires too early, so you can use

new Handler().postDelay(Runnable, timeInMilis)

to dismiss preview image.

3) Add OnTouchListener with any gesture detection to you VideoView. Here is an example of what I'm using now:

    @Overridepublic void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_video);    mGestureDetector = new GestureDetector(this, mGestureListener);    ((VideoView) findViewById(R.id.activity_video_videoview)).setOnTouchListener(mTouchListener);}    private OnTouchListener mTouchListener = new OnTouchListener() {    @Override    public boolean onTouch(View v, MotionEvent event) {        mGestureDetector.onTouchEvent(event);        return true;    }};private SimpleOnGestureListener mGestureListener = new SimpleOnGestureListener() {@Overridepublic boolean onSingleTapConfirmed(MotionEvent e) {    if(mVideoView.isPlaying())        mVideoView.pause();    else        mVideoView.start();    return true;};};

It starts/stops playing by a tap.