How to retrieve the video thumbnail in Android - android

My sdcard video folder contains number of .mp4 video files.
According to my requirement I want to list down those video files in my android application listview with their "Thumbnail" and "Name". BTW I plan to use Picasso or Universal image loader for image caching. Please tell me anyone know how to do?

import android.provider.MediaStore.Video.Thumbnails;
You can get two preview thumbnail sizes from the video:
Thumbnails.MICRO_KIND for 96 x 96
Thumbnails.MINI_KIND for 512 x 384 px
use this code
String filePath = "/sdcard/DCIM/Camera/my_video.mp4"; //change the location of your file!
ImageView imageview_mini = (ImageView)findViewById(R.id.thumbnail_mini);
ImageView imageview_micro = (ImageView)findViewById(R.id.thumbnail_micro);
Bitmap bmThumbnail;
bmThumbnail = ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MINI_KIND);
imageview_mini.setImageBitmap(bmThumbnail);
Check this link

Related

How to save images in .thumbnail folder with proper format?

I need to download images from server and store as thumbnails directly.
and for display images also i need to use images from .thumbnails folder directly. i am not getting how to create and save images as .thumbnail . and how to use images from that .thumbnail file.i searched online but everywhere only this below code present.
Bitmap thumb = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(file.getPath()), width, height);
any help?
Please check below code which helps you.
Follow below steps:
Calculate the maximum possible inSampleSize that still yields an image larger than your target.
Load the image using BitmapFactory.decodeFile(file, options), passing inSampleSize as an option.
Resize to the desired dimensions using Bitmap.createScaledBitmap().
Now you have your bitmap ready and you can save it any where using the following code
Bitmap thumbnail;
File thumbnailFile = ...;
FileOutputStream fos = new FileOutputStream(thumbnailFile);
thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, fos);
fos.flush();
fos.close();
hope it helps you and save your time.
Or use Glide library which store image as a full image and 1 thmbnail image which is power caching library which loads image quickly and once download image after load image from cache not from network.
Below is a Glide link please read it advantages and features and after used into your applications.
https://github.com/bumptech/glide

Fastest way to open list of videos Thumbnails

I would like to know what is the fastest way to read Thumbnail of a video?
My problem is that I've had a couple of videos files and I need to get the thumbnail from all of them.
For now I'm using :
thumb = ThumbnailUtils.createVideoThumbnail(FullPath,
MediaStore.Images.Thumbnails.MICRO_KIND);
This is working good if I have only one video, but if I have even 6 videos it can take a 3 seconds to read all of the thumbnail .
Is someone know another way to read thumbnails that is faster than this mechanism?
Thanks
do like this
ImageView thumbnail_mini = (ImageView)findViewById(R.id.thumbnail_mini);
ImageView thumbnail_micro = (ImageView)findViewById(R.id.thumbnail_micro);
Bitmap bmThumbnail;
// MICRO_KIND: 96 x 96 thumbnail
bmThumbnail = ThumbnailUtils.createVideoThumbnail(filePath,
Thumbnails.MICRO_KIND);
thumbnail_micro.setImageBitmap(bmThumbnail);
// MINI_KIND: 512 x 384 thumbnail
bmThumbnail = ThumbnailUtils.createVideoThumbnail(filePath,
Thumbnails.MINI_KIND);
thumbnail_mini.setImageBitmap(bmThumbnail);

Generate Thumbnail from server video link android

Is it possible in android to get thumbnail of any kind of video of someone has a url link of that video only and video can be from any source like youtube or whatever is source.Please tell me if it is possible or not.Here is my java code by which i am trying to get a thumbnail of youtube video..
public class MainActivity extends Activity {
String path = "http://www.youtube.com/watch?v=HMMEODhZUfA";
Bitmap bm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView image_View = (ImageView) findViewById(R.id.image);
bm = ThumbnailUtils.createVideoThumbnail(path,
MediaStore.Images.Thumbnails.MICRO_KIND);
image_View.setImageBitmap(bm);
}
and this is my xml..
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/hello_world" />
</LinearLayout>
I dont think u can generate the thumbnail of the video by just giving the video link to the ThumbnailManager,
2 approaches which i can suggest is
The server which is storing the video should store the thumbnail of
the video as well so that u can directly download the thumbnail
image
download video and get thumbnail out of that.This approach is not right anyways.
If you are using some third party server eg. youtube or something then they will be having the separate link for thumbnail of video.
If your video link is server link then use below code
To get thumbnail from the URL, i only got one solution till now,
You have to use This library
It Supports file, http, https, mms, mmsh and rtmp protocols Supports aac, acc+, avi, flac, mp2, mp3, mp4, ogg, 3gp and more! formats (audio and video):
If you want to get thumbnail from youtube then consider below code
Thumbnail (480x360 pixels) http://i1.ytimg.com/vi/oB1CUxX1JJE/0.jpg
Thumbnail (120x90 pixels) http://i1.ytimg.com/vi/oB1CUxX1JJE/1.jpg
Thumbnail (120x90 pixels) http://i1.ytimg.com/vi/oB1CUxX1JJE/2.jpg
Thumbnail (120x90 pixels) http://i1.ytimg.com/vi/oB1CUxX1JJE/3.jpg
Thumbnail (480x360 pixels)
http://i1.ytimg.com/vi/oB1CUxX1JJE/hqdefault.jpg
Thumbnail (320x180 pixels)
http://i1.ytimg.com/vi/oB1CUxX1JJE/mqdefault.jpg
Thumbnail (120x90 pixels)
http://i1.ytimg.com/vi/oB1CUxX1JJE/default.jpg
Thumbnail (640x480 pixels)
http://i1.ytimg.com/vi/oB1CUxX1JJE/sddefault.jpg
Thumbnail (1920x1080 pixels)
http://i1.ytimg.com/vi/oB1CUxX1JJE/maxresdefault.jpg
http://img.youtube.com/vi/VIDEO_ID/default.jpg
Check this one..
Replace VIDEO_ID with video id. e.g:
http://img.youtube.com/vi/z99cgIIVuyo/default.jpg
Define your server link,
String path = "http://yourSeverLink/foldername/test.mp4";
then take one imageview like,
ImageView video_thumbnail;
Bitmap bm;
and define in onCreate method.
video_thumbnail = (ImageView) findViewById(R.id.video_one);
now for getting thumbnail use this,
bm = ThumbnailUtils.createVideoThumbnail(path,
MediaStore.Images.Thumbnails.MICRO_KIND);
// For setting that thumnail to imageview use this below code
video_one.setImageBitmap(bm);

How to get thumbnail of video file in android

I have a video file in my sdcard. I would like to show a preview of this video in my ImageView . I know that there is a API:
ThumbnailUtils.createVideoThumbnail(videoFile,
MediaStore.Images.Thumbnails.MINI_KIND)
but it always returns null, is there any alternative?
Its working for me
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Images.Thumbnails.MINI_KIND);
please check once, if you are passing path of video file .
MediaStore.Images.Thumbnails.MINI_KIND and MediaStore.Video.Thumbnails.MINI_KIND are both integers with value 1
So try this first
Bitmap bmp = ThumbnailUtils.createVideoThumbnail(videoPath,1);

Why do I get IOException while creating images using lwuit?

I am getting IOException when I try to create image in lwuit.
the following is the code :
InputStream is = img.getResourceAsStream();
Image img = Image.createImage(is);
the actual size of images are 1 mb and above. Where I am able to create images of 100 or 200 kb in size with the same code.
Thanks.
Yes the size of your images is the reason
try to resize your images using this site
http://www.picresize.com/

Categories

Resources