How to Set the Preview Image in Videoview Before Playing

Set thumbnail to an Intent for VideoView

I solve the problem using MediaMetaDataRetriever.

The code goes like this-

public static Bitmap retriveVideoFrameFromVideo(String videoPath)
throws Throwable
{
Bitmap bitmap = null;
MediaMetadataRetriever mediaMetadataRetriever = null;
try
{
mediaMetadataRetriever = new MediaMetadataRetriever();
if (Build.VERSION.SDK_INT >= 14)
mediaMetadataRetriever.setDataSource(videoPath, new HashMap<String, String>());
else
mediaMetadataRetriever.setDataSource(videoPath);
// mediaMetadataRetriever.setDataSource(videoPath);
bitmap = mediaMetadataRetriever.getFrameAtTime(-1,MediaMetadataRetriever.OPTION_CLOSEST);
}
catch (Exception e)
{
e.printStackTrace();
throw new Throwable(
"Exception in retriveVideoFrameFromVideo(String videoPath)"
+ e.getMessage());

}
finally
{
if (mediaMetadataRetriever != null)
{
mediaMetadataRetriever.release();
}
}
return bitmap;
}

Note that : Because my video link was in the form of server URL, that's why createThumnailUtils was returning a null when video Url was passed through it.

The below code works fine when the video is coming from local storage.

Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail("URL", MediaStore.Images.Thumbnails.MINI_KIND);

BitmapDrawable bitmapD = new BitmapDrawable(thumbnail);
VideoView.setBackground(Drawable bitmapD);

Hope this helps someone!!

Issue displaying thumbnail image in VideoView

VideoView is a subclass of SurfaceView, which has some special behaviors in terms of its display. SurfaceView contents are actually drawn in a window underneath the view hierarchy and the view simply acts as a hole in the current window so the contents are visible. Because of this, if you apply anything to the view itself (like a background), it will actually be Z-Ordered on top of the video content. In addition, if you place anything underneath the VideoView, it also will not be visible because of this "hole".

If you want to display content in this space while the video is not playing, it will either need to be in a separate View laid out on top of the VideoView that you can hide/show when the video playback state changes, or you need to set/clear the background image you have set when the video playback state changes.

HTH!

Android Video View Thumbnail?

ThumbnailUtils is an easy-to use API for generating thumbnails from arbitrary filesystem paths. It is available in API level 8.

Check out ThumbnailUtils.createVideoThumbnail:

Bitmap thumb = ThumbnailUtils.createVideoThumbnail(path,
MediaStore.Images.Thumbnails.MINI_KIND);

How to make a VideoView Preview UI in Android?

int id = **"The Video's ID"**
ImageView iv = (ImageView ) convertView.findViewById(R.id.imagePreview);
ContentResolver crThumb = getContentResolver();
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id, MediaStore.Video.Thumbnails.MICRO_KIND, options);
iv.setImageBitmap(curThumb);

Also you can use Glide for this

Glide  
.with( context )
.load( Uri.fromFile( new File( filePath ) ) )
.into( imageViewGifAsBitmap );


Related Topics



Leave a reply



Submit