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);
}
});
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
I am showing number of dailymotion videos in ListView, i want to try to make thumbnail image from dailymotion video, but i am not getting any way to make thumb.
Have you any idea about it!!!
https://api.dailymotion.com/video/{#id}?fields=thumbnail_medium_url,thumbnail_small_url,thumbnail_large_url
And you have following options and you can pass either one or all:
thumbnail_large_url (320px by 240px)
thumbnail_medium_url (160px by 120px)
thumbnail_small_url (80px by 60px)
https://api.dailymotion.com/video/x26ezrb?fields=thumbnail_medium_url,thumbnail_small_url,thumbnail_large_url
{
"thumbnail_medium_url": "http://s1.dmcdn.net/HRnTi/160x120-JQs.jpg",
"thumbnail_small_url": "http://s1.dmcdn.net/HRnTi/80x60-iBI.jpg",
"thumbnail_large_url": "http://s1.dmcdn.net/HRnTi/x240-oi8.jpg"
}
I am developping an Android application and I encouter problem to get thumbnail of video.
My question is simple. I know how to get thumbnail for Youtube or Dailymotion but is there a way to do the same for a video like this one : http://download.wavetlan.com/SVV/Media/HTTP/MP4/ConvertedFiles/MediaCoder/MediaCoder_test3_1m10s_MPEG4SP_VBR_516kbps_320x240_25fps_MPEG1Layer3_CBR_320kbps_Stereo_44100Hz.mp4
I want to get a frame at time T for every video.
I tried this :
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(m_Video.getM_Urlvideo(),
MediaStore.Images.Thumbnails.MINI_KIND);
m_Video.getM_Urlvideo() is returning my video url..
It doesn't work, anyone has an idea ?
Thank you
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 am trying to create a video thumbnail for a file :
1- the file is located on YouTube.
2- I would start an implicit intent for Andriod OS to play this file using:
Intent intent= new Intent(Intent.ACTION_VIEW, Uri.parse(youTubeVideoWebPath));
startActivity(intent);
where
String youTubeVideoWebPath = "http://www.youtube.com/watch?feature=player_detailpage&v=OZJalBmtGnQ";
after searching some posts on the forum, I found it could be either:
1- VideoView and set its background with the Thumbnail that I will extract from the video Or
2- ImageView which sets its source/background with the extracted Thumbnail
when an item (whether VideoView or ImageView) is clicked, I will send the previous mentioned intent.
since I am not going to control playing the video by my application, I guess that it is better to use ImageView, right?
Secondly,
I would like to create a video Thumbnail for that remote file so what is the best/easiest way to do that?
For me, after doing more search on the forum, I found the following method:
Bitmap thumbAsBitmap = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.MINI_KIND);
But it always returns null, I dont know why although that I passed it:
filePath: the web path of the file mentioned above
second argument: not sure whether it should be MediaStore.Video.Thumbnails.MINI_KIND or
MediaStore.Images.Thumbnails.MINI_KIND?
I can only find posts related to extracting VideoThumbnail from files saved in internal/external memory, nothing related to remote files such as my case.
Why not fetch YouTube thumbnail? It looks quite simple. Once you got video URL, like this:
https://www.youtube.com/watch?v=dRpFF5Dm-k0
you extract video ID (which in this case is dRpFF5Dm-k0) and your thumbnail is at:
http://i1.ytimg.com/vi/<VIDEOID>/default.jpg
so in this case:
http://i1.ytimg.com/vi/dRpFF5Dm-k0/default.jpg
Not sure if that works for any video (I just found that out to answer your question), but at least it is a good start :)