<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ImageView
android:id="@+id/thumbnail_micro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/thumbnail_mini"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Java Code
package com.exercise.AndroidThumbnailUtils;
import android.app.Activity;
import android.graphics.Bitmap;
import android.media.ThumbnailUtils;
import android.os.Bundle;
import android.provider.MediaStore.Video.Thumbnails;
import android.widget.ImageView;
public class AndroidThumbnailUtils extends Activity {
String filePath = "/sdcard/Video/Royal Wedding.mp4";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView thumbnail_mini = (ImageView)findViewById(R.id.thumbnail_mini);
ImageView thumbnail_micro = (ImageView)findViewById(R.id.thumbnail_micro);
Bitmap bmThumbnail;
// MICRO_KIND: 96 x 96 thumbnail
bmThumbnail = ThumbnailUtils.createVideoThumbnail(filePath,
Thumbnails.MICRO_KIND);
thumbnail_micro.setImageBitmap(bmThumbnail);
// MINI_KIND: 512 x 384 thumbnail
bmThumbnail = ThumbnailUtils.createVideoThumbnail(filePath,
Thumbnails.MINI_KIND);
thumbnail_mini.setImageBitmap(bmThumbnail);
}
}
Download the files.
Related article:
- ThumbnailUtils
- Display Video thumbnail in ListView