How to Generate a Thumbnail from a Video Url in Android

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

How can i get video thumbnail from remote url in android

I have solve the issue by using GLide 4.x. I have find another solution by using MediaMetadataRetriever. But it's not feasible to use MediaMetadataRetriever in a recycle view because it runs on main thread and cause ANR. The code that works for me is below.

RequestOptions requestOptions = new RequestOptions();
Glide.with(context)
.load("Your URL")
.apply(requestOptions)
.thumbnail(Glide.with(context).load("Your URL"))
.into(holder.img_video_attachment_preview);

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 create thumbnail of video url form server

Try this Create new AsyncTask like this

public class DownloadImage extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;

public DownloadImage(ImageView bmImage) {
this.bmImage = (ImageView ) bmImage;
}

protected Bitmap doInBackground(String... urls) {
Bitmap myBitmap = null;
MediaMetadataRetriever mMRetriever = null;
try {
mMRetriever = new MediaMetadataRetriever();
if (Build.VERSION.SDK_INT >= 14)
mMRetriever.setDataSource(urls[0], new HashMap<String, String>());
else
mMRetriever.setDataSource(urls[0]);
myBitmap = mMRetriever.getFrameAtTime();
} catch (Exception e) {
e.printStackTrace();

} finally {
if (mMRetriever != null) {
mMRetriever.release();
}
}
return myBitmap;
}

protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}

Than call this AsyncTask like this

   new DownloadImage(YourImageView).execute("Your URL");

EDIT

Or you can also use Glide to create thumbnail of video from url

 RequestOptions requestOptions = new RequestOptions();
requestOptions.placeholder(R.drawable.placeholder_card_view);
requestOptions.error(R.drawable.placeholder_card_view);

Glide.with(getContext())
.load(path)
.apply(requestOptions)
.thumbnail(Glide.with(getContext()).load(path))
.into(ivVideoThumbnail);

How to get video thumbnail from YouTube URL and set it to image view in android

You can use YouTube API v3 to retrieve related video thumbnail info like title, image and length:

https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet&fields=items/snippet(title,thumbnails),items/contentDetails/duration&key={{ YOUR_API_KEY }}&id={{ YOUR_YOUTUBE_VIDEO_ID }}

Or this url if you only want to get only thumbnail image with medium size:

https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet&fields=items/snippet(title,thumbnails/medium/url),items/contentDetails/duration&key={{ YOUR_API_KEY }}&id={{ YOUR_YOUTUBE_VIDEO_ID }}

Your response may look like this:

{
"items": [
{
"snippet": {
"title": "F..k This S..t I'm Out",
"thumbnails": {
"medium": {
"url": "https://i.ytimg.com/vi/5FjWe31S_0g/mqdefault.jpg"
}
}
},
"contentDetails": {
"duration": "PT25S"
}
}
]
}


Related Topics



Leave a reply



Submit