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);
Related
I'm trying to display a video thumbnail of the post.
The user is able to enter a link from Youtube, Mixer, and Twitch videos and I'm a noob so I'm not sure how to get an actual thumbnail from that videos.
Here is the code that I'm using right now, it's working well, but I don't want all videos to show exactly the same thumbnails so I'd like to show an actual thumbnail.
when (post.type){
"twitch" -> {
post_image.setImageResource(R.drawable.twitch)
}
"youtube" -> {
post_image.setImageResource(R.drawable.youtube)
}
"mixer" -> {
post_image.setImageResource(R.drawable.mixer)
}
else -> {
post_image.setImageResource(R.drawable.image_placeholder)
}
}
As you've mentioned,
I don't want all videos to show exactly the same thumbnails so I'd like to show an actual thumbnail.
You need to use the video ID to fetch the thumbnail of the video like the following:
String url = "https://www.youtube.com/watch?v=en7IK3iH3wI"
String videoId = url.split("v=")[1]; //for this, the extracted id is "en7IK3iH3wI"
String tempThumbnailDefault = "http://img.youtube.com/vi/"+videoId+"/default.jpg" //default quality thumbnail
String tempThumbnailStandard = "http://img.youtube.com/vi/"+videoId+"/sddefault.jpg"
//standard thumbnail
String tempThumbnailInMaxRes = "http://img.youtube.com/vi/"+videoId+"/maxresdefault.jpg"
//maximum resolution thumbnail
String tempThumbnailInMQ = "http://img.youtube.com/vi/"+videoId+"/mqdefault.jpg" //medium quality thumbnail
String tempThumbnailInHQ = "http://img.youtube.com/vi/"+videoId+"/hqdefault.jpg"
//high quality thumbnail
Then you can use this path to load images with Glide or Picasso like the following:
//If using Glide
Glide.with(this)
.load(tempThumbnailInHQ)
.into(yourImageView);
//If using Picasso
Picasso.with(context)
.load(tempThumbnailInHQ)
.into(yourImageView);
For fetching thumbnail from Twitch, you need to use Twitch API & a registered account on https://glass.twitch.tv. Please refer to this accepted answer for knowing the steps to use it.
Hope this helps!
If you have video url then you can use Glide for video thumbnail.
You can check the doc here https://github.com/bumptech/glide
How to put thumbnail over the youtubeVideoplayer in Layout-xml file of android studio 2.3.2, As I am able to play the youtube video in my app but I want to show the thumbnail of that video before playing video so that it look nice.
you need to get the video's thumbnail seperately
You can get a thumbnail of your YouTube video using this link by replacing VIDEO_ID with your own video's ID.
Show this thumbnail before user plays the video
Every you tube video have unique ID and that is the only difference in each you tube video URL. Like video, every thumbnail alo have unique ID which is of course the same as video which belongs. Basically you have to extract or put unique ID and then download thumbnail using your own methods for downloading bitmaps or using some third party library like Glide. Something like this:
String url = MessageFormat.format("http://img.youtube.com/vi/{0}/hqdefault.jpg", idOfYourVideo);
Glide.with(YourActivityName.this).load(url).asBitmap().into(new
SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super
Bitmap> glideAnimation) {
thumbnail.setImageBitmap(resource);
}
});
I have this path of video in android - file:///storage/emulated/0/Images/nature.mp4 and I want to get the path of the bitmap of the thumbnail extracted from the video and not the bitmap object itself so that I can load the thumbnail using picasso library like for the images url
Picasso.with(con).load(image_url).into(holder.Img);
I've looked at the similar question on the site but it wasn't clear enough for my case.
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
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);