为多媒体文件生成缩略图
1、Video
对于视频,取第一帧作为缩略图,也就是怎样从filePath得到一个Bitmap对象。
private Bitmap createVideoThumbnail(String filePath) { Bitmap bitmap = null; MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try { retriever.setMode(MediaMetadataRetriever.MODE_CAPTURE_FRAME_ONLY); retriever.setDataSource(filePath); bitmap = retriever.captureFrame(); } catch(IllegalArgumentException ex) { // Assume this is a corrupt video file } catch (RuntimeException ex) { // Assume this is a corrupt video file. } finally { try { retriever.release(); } catch (RuntimeException ex) { // Ignore failures while cleaning up. } } return bitmap; } private Bitmap createAlbumThumbnail(String filePath) { Bitmap bitmap = null; MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try { retriever.setMode(MediaMetadataRetriever.MODE_GET_METADATA_ONLY); retriever.setDataSource(filePath); byte[] art = retriever.extractAlbumArt(); bitmap = BitmapFactory.decodeByteArray(art, 0, art.length); } catch(IllegalArgumentException ex) { } catch (RuntimeException ex) { } finally { try { retriever.release(); } catch (RuntimeException ex) { // Ignore failures while cleaning up. } } return bitmap; } Bitmap bm = null; Options op = new Options(); op.inSampleSize = inSampleSize; op.inJustDecodeBounds = false; bm = BitmapFactory.decodeFile(mFile.getPath(), op);