How to Show a Video Thumbnail from a Video Path

how can I show a video thumbnail from a video path?

It is the default way to create a thumbnail.

For Mini Kind

Bitmap thumb;
//MINI_KIND, size: 512 x 384 thumbnail
thumb = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.MINI_KIND);
img_tumbnail.setImageBitmap(thumb);

For Micro Kind

Bitmap thumb;
//MICRO_KIND, size: 96 x 96 thumbnail
thumb= ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MICRO_KIND);
img_tumbnail.setImageBitmap(thumb);

Also, you can use Glide for Url as well as Video path of Device.

Glide.with(context).with(this)
.asBitmap()
.load(videoFilePath) // or URI/path
.into(imgView); //imageview to set thumbnail to

also, you can resize thumbnail by using .override(50,50) with Glide.

How to create a video thumbnail from a video file path in Android?

You can use ThumbnailUtils class to get Video thumbnail of Video file.

createVideoThumbnail() is method which return Bitmap (thumbnail) of video from video file path.

From Android Docs:

public static Bitmap createVideoThumbnail (String filePath, int kind)

Create a video thumbnail for a video. May return null if the video is
corrupt or the format is not supported.

You can create VideoThumbnail from sdcard path like this.

Bitmap thumb = ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MINI_KIND);

Using ThumbnailUtils, you can create thumbnail of two types.

  1. MediaStore.Images.Thumbnails.MICRO_KIND type will generate thumbnail of size 96 x 96.

  2. MediaStore.Images.Thumbnails.MINI_KIND type will generate thumbnail of size 512 x 384.

I hope it helps!

How do I get thumbnail of a video in android

You can use glide. its automatically set thumb image of video.

Glide is also able to display the thumbnail of videos, as long as they're stored on the phone. Let's assume you get the file path by letting the user select a video: Based on this document https://futurestud.io/tutorials/glide-displaying-gifs-and-videos

String filePath = "/storage/emulated/0/Pictures/example_video.mp4";

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

How to get the video thumbnail path, and not the bitmap

First, you need to know the content uri of the file. If you have the file path, this shows you how to get the content uri.

public static String[] thumbColumns = { MediaStore.Video.Thumbnails.DATA };
public static String[] mediaColumns = { MediaStore.Video.Media._ID };

public static String getThumbnailPathForLocalFile(Activity context,
Uri fileUri) {

long fileId = getFileId(context, fileUri);

MediaStore.Video.Thumbnails.getThumbnail(context.getContentResolver(),
fileId, MediaStore.Video.Thumbnails.MICRO_KIND, null);

Cursor thumbCursor = null;
try {

thumbCursor = context.managedQuery(
MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID + " = "
+ fileId, null, null);

if (thumbCursor.moveToFirst()) {
String thumbPath = thumbCursor.getString(thumbCursor
.getColumnIndex(MediaStore.Video.Thumbnails.DATA));

return thumbPath;
}

} finally {
}

return null;
}

public static long getFileId(Activity context, Uri fileUri) {

Cursor cursor = context.managedQuery(fileUri, mediaColumns, null, null,
null);

if (cursor.moveToFirst()) {
int columnIndex = cursor
.getColumnIndexOrThrow(MediaStore.Video.Media._ID);
int id = cursor.getInt(columnIndex);

return id;
}

return 0;
}

Reference: http://androidcodezs.blogspot.com/2013/10/android-thumbnail-from-video.html

Android: Is it possible to display video thumbnails?

If you are using API 2.0 or newer this will work.

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);

Is it possible to Generate a thumbnail from a video url in android

It is not possible to create thumbnail from steaming link, you have to show it from server. Better upload a thumbnail along the video.
Use the below code to generate thumbnail

Bitmap bitmap = ThumbnailUtils.createVideoThumbnail("picturePath", MediaStore.Video.Thumbnails.MINI_KIND);


Related Topics



Leave a reply



Submit