1, get video thumbnails have two methods (1) through the content provider to get (2) people to create thumbnails
(1) The disadvantage is that the media library must be updated to see the latest video thumbnails
[Java]
Copy Code code as follows:
/**
* @param context
* @param cr
* @param Videopath
* @return
*/
public static Bitmap Getvideothumbnail (context context, Contentresolver CR, String videopath) {
Contentresolver TESTCR = Context.getcontentresolver ();
string[] projection = {MediaStore.Video.Media.DATA, mediastore.video.media._id,};
String Whereclause = MediaStore.Video.Media.DATA + "= '" + Videopath + "'";
Cursor Cursor = testcr.query (MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, Whereclause,
NULL, NULL);
int _id = 0;
String Videopath = "";
if (cursor = NULL | | cursor.getcount () = 0) {
return null;
}
if (Cursor.movetofirst ()) {
int _idcolumn = Cursor.getcolumnindex (mediastore.video.media._id);
int _datacolumn = Cursor.getcolumnindex (MediaStore.Video.Media.DATA);
do {
_id = Cursor.getint (_idcolumn);
Videopath = cursor.getstring (_datacolumn);
while (Cursor.movetonext ());
}
Cursor.close ();
Bitmapfactory.options Options = new Bitmapfactory.options ();
Options.indither = false;
Options.inpreferredconfig = Bitmap.Config.RGB_565;
Bitmap Bitmap = MediaStore.Video.Thumbnails.getThumbnail (CR, _id, Images.Thumbnails.MINI_KIND,
Options);
return bitmap;
}
/**
* @param context
* @param cr
* @param Videopath
* @return
*/
public static Bitmap Getvideothumbnail (context context, Contentresolver CR, String videopath) {
Contentresolver TESTCR = Context.getcontentresolver ();
string[] projection = {MediaStore.Video.Media.DATA, mediastore.video.media._id,};
String Whereclause = MediaStore.Video.Media.DATA + "= '" + Videopath + "'";
Cursor Cursor = testcr.query (MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, Whereclause,
NULL, NULL);
int _id = 0;
String Videopath = "";
if (cursor = NULL | | cursor.getcount () = 0) {
return null;
}
if (Cursor.movetofirst ()) {
int _idcolumn = Cursor.getcolumnindex (mediastore.video.media._id);
int _datacolumn = Cursor.getcolumnindex (MediaStore.Video.Media.DATA);
do {
_id = Cursor.getint (_idcolumn);
Videopath = cursor.getstring (_datacolumn);
while (Cursor.movetonext ());
}
Cursor.close ();
Bitmapfactory.options Options = new Bitmapfactory.options ();
Options.indither = false;
Options.inpreferredconfig = Bitmap.Config.RGB_565;
Bitmap Bitmap = MediaStore.Video.Thumbnails.getThumbnail (CR, _id, Images.Thumbnails.MINI_KIND,
Options);
return bitmap;
(2) People spend a little time creating thumbnails
[Java]
Copy Code code as follows:
/**
* Get video thumbnails
* @param Videopath
* @param width
* @param height
* @param kind
* @return
*/
Private Bitmap Getvideothumbnail (String videopath, int width, int height, int kind) {
Bitmap Bitmap = null;
Bitmap = Thumbnailutils.createvideothumbnail (Videopath, kind);
Bitmap = Thumbnailutils.extractthumbnail (bitmap, width, height, thumbnailutils.options_recycle_input);
return bitmap;
}
/**
* Get video thumbnails
* @param Videopath
* @param width
* @param height
* @param kind
* @return
*/
Private Bitmap Getvideothumbnail (String videopath, int width, int height, int kind) {
Bitmap Bitmap = null;
Bitmap = Thumbnailutils.createvideothumbnail (Videopath, kind);
Bitmap = Thumbnailutils.extractthumbnail (bitmap, width, height, thumbnailutils.options_recycle_input);
return bitmap;
}
2. Thumbnail image
[Java]
Copy Code code as follows:
/**
*
* @param context
* @param cr
* @param ImagePath
* @return
*/
public static Bitmap Getimagethumbnail (context context, Contentresolver CR, String ImagePath) {
Contentresolver TESTCR = Context.getcontentresolver ();
string[] projection = {MediaStore.Images.Media.DATA, mediastore.images.media._id,};
String Whereclause = MediaStore.Images.Media.DATA + "= '" + ImagePath + "'";
Cursor Cursor = testcr.query (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, Whereclause,
NULL, NULL);
int _id = 0;
String ImagePath = "";
if (cursor = NULL | | cursor.getcount () = 0) {
return null;
}
if (Cursor.movetofirst ()) {
int _idcolumn = Cursor.getcolumnindex (mediastore.images.media._id);
int _datacolumn = Cursor.getcolumnindex (MediaStore.Images.Media.DATA);
do {
_id = Cursor.getint (_idcolumn);
ImagePath = cursor.getstring (_datacolumn);
while (Cursor.movetonext ());
}
Cursor.close ();
Bitmapfactory.options Options = new Bitmapfactory.options ();
Options.indither = false;
Options.inpreferredconfig = Bitmap.Config.RGB_565;
Bitmap Bitmap = MediaStore.Images.Thumbnails.getThumbnail (CR, _id, Images.Thumbnails.MINI_KIND,
Options);
return bitmap;
}
/**
*
* @param context
* @param cr
* @param ImagePath
* @return
*/
public static Bitmap Getimagethumbnail (context context, Contentresolver CR, String ImagePath) {
Contentresolver TESTCR = Context.getcontentresolver ();
string[] projection = {MediaStore.Images.Media.DATA, mediastore.images.media._id,};
String Whereclause = MediaStore.Images.Media.DATA + "= '" + ImagePath + "'";
Cursor Cursor = testcr.query (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, Whereclause,
NULL, NULL);
int _id = 0;
String ImagePath = "";
if (cursor = NULL | | cursor.getcount () = 0) {
return null;
}
if (Cursor.movetofirst ()) {
int _idcolumn = Cursor.getcolumnindex (mediastore.images.media._id);
int _datacolumn = Cursor.getcolumnindex (MediaStore.Images.Media.DATA);
do {
_id = Cursor.getint (_idcolumn);
ImagePath = cursor.getstring (_datacolumn);
while (Cursor.movetonext ());
}
Cursor.close ();
Bitmapfactory.options Options = new Bitmapfactory.options ();
Options.indither = false;
Options.inpreferredconfig = Bitmap.Config.RGB_565;
Bitmap Bitmap = MediaStore.Images.Thumbnails.getThumbnail (CR, _id, Images.Thumbnails.MINI_KIND,
Options);
return bitmap;
}