Generate Thumbnail from server video link android

2019-05-05 19:45发布

问题:

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>

回答1:

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

  1. 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
  2. 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.



回答2:

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



回答3:

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



回答4:

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);