Android - how to set a thumbnail on a VideoView with a uri source?

android video view library
custom videoview android example
mediacontroller; videoview android example
videoview getcurrentposition
videoview autoplay android
fast-video view for android
load video in videoview android
set thumbnail for video view android

I need to get an image from a uri into my VideoView when it loads. It should disappear and start playing the video when play is hit. This is my VideoView code -

<RelativeLayout
    android:id="@+id/video_frame"
    android:layout_width="fill_parent"
    android:layout_height="300dp"
    android:background="#000"
    >

    <VideoView
        android:id="@+id/video"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        />

    <ImageButton
        android:id="@+id/play_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/ic_media_play"
        />

</RelativeLayout>

This is how I use it -

final VideoView video = (VideoView) convertView.findViewById(R.id.video);

    Uri uri = Uri.parse(submission.getUrl());
    video.setVideoURI(uri);

    final ImageButton playButton = (ImageButton) convertView.findViewById(R.id.play_button);
    video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            playButton.setVisibility(View.VISIBLE);
        }
    });
    playButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (video.isPlaying()){
            }else{
                video.start();
                playButton.setVisibility(View.GONE);
            }
        }

    });

VideoView shows a video. It does not show an image. Similarly, ImageView shows an image. It does not show a video.

So, use a FrameLayout wrapped around an ImageView and a VideoView. Have the ImageView be visible and the VideoView be invisible at the outset. Load the image into the ImageView. When the user clicks your play button, switch the visibility such that the VideoView is now visible and the ImageView is invisible, and start playback of your video.

How to set the preview image in videoview before playing, seekTo( 1 ) because setting . createVideoThumbnail("file path/url", MediaStore. android:focusable="true"> <VideoView android:id="@+id/video_view"  In this android programming source code example, we are going to create VideoView in Android. You can copy and adopt this source code example to your android project without reinventing the wheel. Below is a step by step source code to create VideoView in Android. activity_main.xml

Create a thumpnail of video and show it on ImageView. In case you need to show play button you need another ImageView (with Play button icon). On click of Play icon image view play the video on VideoView.

    imageView.setImageBitmap(ThumbnailUtils.createVideoThumbnail(urlPath, 
    MediaStore.Video.Thumbnails.MICRO_KIND));

VideoView, Register a callback to be invoked when the media file is loaded and ready to go. void, setVideoPath(String path). Sets video path. void, setVideoURI(Uri  In this android programming source code example, we are going to create fullscreen VideoView in Android. You can copy and adopt this source code example to your android project without reinventing the wheel. Below is a step by step source code to create fullscreen VideoView in Android. activity_main.xml

I have created an ImageView for thumbnail like this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:clickable="true"
    android:focusable="true">

 <VideoView
    android:id="@+id/video_view"
    android:layout_width="match_parent"
    android:layout_height="220dp"/>
<ImageView
    android:id="@+id/videoView_thumbnail"
    android:layout_width="match_parent"
    android:layout_height="220dp"
    android:scaleType="centerCrop"/>

</RelativeLayout>

And add setOnPreparedListener and setOnCompletionListener in Java like this way

  VideoView videoView = (VideoView) view.findViewById(R.id.video_view);
  ImageView thumbnailView=(ImageView)view.findViewById(R.id.videoView_thumbnail);

  Glide.with(getApplicationContext()).load(your_Image_Path).into(thumbnailView);
 //you can add progress dialog here until video is start playing;

    mediaController= new MediaController(getContext());
    mediaController.setAnchorView(videoView);
    videoView.setMediaController(mediaController);
    videoView.setKeepScreenOn(true);
    videoView.setVideoPath(your_video_path);
    videoView.start();         //call this method for auto playing video

    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mediaPlayer) {
            thumbnailView.setVisibility(View.GONE);
 //you can Hide progress dialog here when video is start playing;

        }
    });
    videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mediaPlayer) {
            videoView.stopPlayback();
            thumbnailView.setVisibility(View.VISIBLE);

        }
    });

It works for me very well. I hope it's useful for all.

VideoView Tutorial With Example In Android Studio, setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.​fishvideo));. Setting Video From Online Web Source: Step 1: First add internet  After that, we have set video resource to videoView. At last, we set click listener to button that play/pause video in videoView. If video is already playing, we pause the video. otherwise, we play the video when button is clicked. Method videoView.start() is being called to play the video. Method videoView.pause() is being called to pause the

Android Open Source - Camera-Example Main Activity, Android Open Source - Camera-Example Main Activity. Java Source Code ThumbnailUtils; import android.net. private Uri mediaUri; /** * @var private VideoView videoView * @brief The associated VideoView onCreate(​savedInstanceState); // set the orientation based on the layout int orientation = getResources(). VideoView Tutorial With Example In Android Studio. In Android, VideoView is used to display a video file. It can load images from various sources (such as content providers or resources) taking care of computing its measurement from the video so that it can be used for any layout manager, providing display options such as scaling and tinting.

How to set the preview image in videoview before playing , How to set the preview image in videoview before playing setAnchorView(​vvVideos); Uri video = Uri.parse("android.resource://" + BitmapDrawable bitmapDrawable = new BitmapDrawable(thumb); mVideoView. Android VideoView, Android VideoView example tutorial, Android VideoView from URL, Android VideoView custom MediaController, Android play video using VideoView class, Android Studio VideoView example app code.

Using VideoViews, The Hour21VideoView project contains this source code. In both cases, you can use the setVideoUri() method of VideoView. Uri class being defined from a String and the resulting Uri being set to the VideoView in line 3. In this tutorial, you will learn how to stream a remote video by using a MediaController and display it into a VideoView in your Android Application. MediaController is a controller for Media Player such as functions like Play/Pause, Rewind,

Comments
  • my question is probably a bit unclear.. I need for a way to extract an image out of the video itself.. not sure if this is possible.
  • @Suchi: If the video is known to MediaStore, it should have a thumbnail which you can retrieve, typically via an image-loading library (see this sample app). If the video is not known to MediaStore, ThumbnailUtils should be able to extract one, though I have not used it.