Create a thumbnail from the server

Is it possible to get a thumbnail of a video in android that has a link to the url of only this video, and the video can be from any source, such as youtube or something else. Please tell me if this is possible or not. Here is my Java code with which I am trying to get a thumbnail of a 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>
+4
source share
4 answers

I don’t think you can create a thumbnail of a video just by passing the video link to ThumbnailManager,

2 approaches that I can offer

  • The server on which the video is stored must save the thumbnail of the video so that you can directly upload the thumbnail image
  • . .

- , . youtube - .

+5

http://img.youtube.com/vi/VIDEO_ID/default.jpg

.

Replace VIDEO_ID with the video image. for example: http://img.youtube.com/vi/ z99cgIIVuyo /default.jpg

+1
source

Define a server link,

String path = "http://yourSeverLink/foldername/test.mp4";

then take one image for example

ImageView video_thumbnail;
Bitmap bm;

and define in the onCreate method.

video_thumbnail = (ImageView) findViewById(R.id.video_one);

now use this to get thumbnails,

bm = ThumbnailUtils.createVideoThumbnail(path,
                    MediaStore.Images.Thumbnails.MICRO_KIND);
// For setting that thumnail to imageview use this below code
video_one.setImageBitmap(bm);
-2
source

Source: https://habr.com/ru/post/1534975/


All Articles