如何从Android中的.mov文件中获取缩略图?

时间:2014-02-11 05:55:36

标签: android bitmap android-contentresolver android-cursor mediastore

我使用以下代码获取JPGAVI文件的缩略图,但我无法从.mov文件中获取缩略图。

String[] projection_image = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID, };
            String[] projection_video = { MediaStore.Video.Media.DATA, MediaStore.Video.Media._ID, };

            File file = new File(viewTag.mFileNode.mName) ;
            String tempfilePath = file.getPath();

            String whereClause_image = MediaStore.Images.Media.DATA + " = '" + tempfilePath + "'";
            String whereClause_video = MediaStore.Video.Media.DATA + " = '" + tempfilePath + "'";

            ContentResolver cr = getActivity().getContentResolver();
            Cursor image_cursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection_image, whereClause_image, null, null);
            Cursor video_cursor = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection_video, whereClause_video, null, null);

            try {

                if(image_cursor.moveToFirst()){
                    long thumID = image_cursor.getLong(image_cursor.getColumnIndex("_ID"));
                    Bitmap bitmap_image = MediaStore.Images.Thumbnails.getThumbnail(getActivity().getContentResolver(), thumID, Images.Thumbnails.MICRO_KIND, null);

                    viewTag.mThumbnail.setImageBitmap(bitmap_image) ;

                }

                if(video_cursor.moveToFirst()){
                    long thumID = video_cursor.getLong(video_cursor.getColumnIndex("_ID"));
                    Bitmap bitmap_video = MediaStore.Video.Thumbnails.getThumbnail(getActivity().getContentResolver(), thumID, Video.Thumbnails.MICRO_KIND, null);
                    viewTag.mThumbnail.setImageBitmap(bitmap_video) ;               
                }

            } catch (NullPointerException e) {
                // TODO: handle exception
                Log.i(TAG, "cursor---NullPointerException");

                image_cursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection_image, whereClause_image, null, null);
                video_cursor = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection_video, whereClause_video, null, null);

            } finally{
                image_cursor.close();
                video_cursor.close();
            }

有人知道如何在Android中使用MediaStore从.mov文件中获取缩略图吗?

1 个答案:

答案 0 :(得分:1)

Bitmap thumb = ThumbnailUtils.createVideoThumbnail(path,
    MediaStore.Images.Thumbnails.MINI_KIND);