Reputation: 4633
I have a problem with creating Thumbnail from mp4 file which is in assets folder. Try to enter different asset`s path but no effect. How can I fix it?
That`s my piece of adapter code:
VideoEntry video = videos.get(position);
holder.txtTitle.setText(video.getTitle());
holder.imgIcon.setImageBitmap(ThumbnailUtils.createVideoThumbnail("file:///android_asset/videos/Core/Superman.mp4", Thumbnails.MICRO_KIND));
What is wrong?
Solution:
AssetManager am = getAssets();
InputStream ims = am.open("images/" + category + "/" + item.replace(" ", "_").replace(".mp4", ".png").toLowerCase());
Drawable d = Drawable.createFromStream(ims, null);
holder.imgIcon.setImageDrawable(d);
Upvotes: 3
Views: 5449
Reputation: 49
This Worked For Me
Bitmap getThumbnailOf(AssetFileDescriptor afd, int atTime) {
Bitmap bitmap = null;
MediaMetadataRetriever retriever = null;
if (afd != null && afd.getFileDescriptor().valid()) try {
retriever = new MediaMetadataRetriever();
retriever.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
bitmap = retriever.getScaledFrameAtTime(atTime, MediaMetadataRetriever.OPTION_CLOSEST, 1280, 720);
} else {
bitmap = retriever.getFrameAtTime(atTime);
}
afd.close();
retriever.release();
Log.i("TAG", "getting bitmap process done");
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
By Giving input as
getThumbnailOf(getAssets().openFd("videos/Core/Superman.mp4"), 500000)
Upvotes: 1
Reputation: 1526
Assets it's app static resoureces' folder. You can create tumbnails for this video mannually and also put it to assets.
Upvotes: 0
Reputation: 40218
ThumbnailUtils.createVideoThumbnail()
just queries an existing thumbnail from MediaStore
or forces MediaStore
to create it if it doesn't exist. This means that you can't create a thumbnail for a video file that isn't available for MediaStore
, as it's an asset of your application and not an actual file on the SD card. You can extract your file to SD card or just provide a thumbnail created by yourself in another application. Hope this helps.
Upvotes: 8