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);
Related
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
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);
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);
I have 3 or 4 image paths that I use to load an image so I set it to an imageview. Why does it take long? Or better asking is there a way to make it faster? At the end of the day I am loading to fit an imageview of less than 60 dp hight and width
Uri mainImgeUri = Uri.parse(imagePath);
InputStream imageStream;
try {
imageStream = mActiviy.getContentResolver().openInputStream(mainImgeUri);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream, null, options);
mainImageIV.setImageBitmap(yourSelectedImage);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
USE CASE:
What happens is that a user will add 5 images (and he get to choose them from Gallery which is mostly taken by phone camera). He hit save and my app stores the path to them in an sqlite database. Then when the user opens the app again to see them, my app query the db to get the paths to all the images and executes the code above x number of times so all the image views are loaded with the intended images
Take a look at http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
It explains how to calculate the correct inSampleSize based on the required dimensions of the output image. It also explains how to reference large bitmaps without having to load all their pixel data into memory.
The idea is that you resample bigger images and only load the smaller ones into memory making the whole process much more efficient. The example code is accessing a bitmap from resources, but this can easily be modified for your needs.
The important things to look out for in the example are inJustDecodeBounds and calculateInSampleSize.
So i am trying to load a bunch of thumbnails (possibly up to 100+) from the web, and I seem to be running out of memory around 30 on the emulator, and around 80-85 on the phone itself.
This is not going to work but there has to be a way-
I even tried saving the images to cache memory and loading from there, but it still runs out of memory.
What is the correct way to load a lot of web thumbnail images?
each image is about 50 kb, im basically adding the imageViews dynamically through a method i made called CreateImage. This pretty much loads each thumbnail based on the URL and image name, and sets it in a dynamic imageView in a horizontalScollView.
private void createImages(String URL, String imageName){
ImageView ImageThumbnails = new ImageView(this);
ImageThumbnails.setId(ImageThumbName);
ImageThumbnails.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
ImageThumbnails.getLayoutParams().height = 85;
ImageThumbnails.getLayoutParams().width = 85;
ImageThumbnails.setPadding(4, 4, 4, 4);
ImageThumbnails.setScaleType(ImageView.ScaleType.FIT_XY);
ImageThumbnails.setOnClickListener(this);
String path = Environment.getExternalStorageDirectory()+ "/" + imageName;
File imgFile = new File(path);
if(imgFile.exists())
{
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
Bitmap bmpCompressed = Bitmap.createScaledBitmap(myBitmap, 85, 85, true);
ImageThumbnails.setImageBitmap(bmpCompressed);
}
ll.addView(ImageThumbnails);
}
Thanks in advance,
You should read those articles on the Android portal that explain exactly how to do it and provide the code:
Displaying bitmaps: http://developer.android.com/training/displaying-bitmaps/index.html
Loading large bitmaps: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
Use AsyncTask to download each image individually and save it to disk (individually). Thats what I did for 30+ images for a Magazine App.
I think your problem will be solved with lazy list adapter. Try this example LazyList