List of usage examples for android.media MediaMetadataRetriever getFrameAtTime
public Bitmap getFrameAtTime()
From source file:Main.java
public static Bitmap getVideoScreenShot(String filePath) { MediaMetadataRetriever media = new MediaMetadataRetriever(); media.setDataSource(filePath);// ww w.ja v a 2s .c om Bitmap bitmap = media.getFrameAtTime(); media.release(); return bitmap; }
From source file:Main.java
public static Bitmap getFrameAtTime(String path) { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(path, new HashMap<String, String>()); return retriever.getFrameAtTime(); }
From source file:Main.java
public static Bitmap getVideoThumbnail(String filePath) { Bitmap bitmap = null;/*from www . ja va 2 s . c om*/ MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try { retriever.setDataSource(filePath); bitmap = retriever.getFrameAtTime(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (RuntimeException e) { e.printStackTrace(); } finally { try { retriever.release(); } catch (RuntimeException e) { e.printStackTrace(); } } return bitmap; }
From source file:com.online.fullsail.SaveWebMedia.java
private Bitmap getVideoFrame(String uri) { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try {/*from w w w . ja va2 s. c o m*/ if (Integer.parseInt(Build.VERSION.SDK) > Build.VERSION_CODES.GINGERBREAD) { retriever.setDataSource(uri); return retriever.getFrameAtTime(); } else { retriever.setMode(MediaMetadataRetriever.MODE_CAPTURE_FRAME_ONLY); retriever.setDataSource(uri); return retriever.captureFrame(); // These items were handled by the custom android media class // Despite being marked errors, they compile without an issue } } catch (IllegalArgumentException ex) { ex.printStackTrace(); } catch (RuntimeException ex) { ex.printStackTrace(); } finally { try { retriever.release(); } catch (RuntimeException ex) { } } return null; }
From source file:com.nostra13.universalimageloader.core.decode.ContentImageDecoder.java
private Bitmap makeVideoThumbnailFromMediaMetadataRetriever(MediaMetadataRetriever retriever) { if (retriever == null) return null; Bitmap thumbnail = null;/*w w w . j av a2 s . c o m*/ byte[] picture = retriever.getEmbeddedPicture(); if (picture != null) { Log8.d(); thumbnail = BitmapFactory.decodeByteArray(picture, 0, picture.length); if (thumbnail != null) { Log8.d(thumbnail.getWidth(), thumbnail.getHeight()); } } else { Log8.d(); } if (thumbnail == null) { Log8.d(); thumbnail = retriever.getFrameAtTime(); if (thumbnail != null) { Log8.d(thumbnail.getWidth(), thumbnail.getHeight()); } } if (thumbnail == null) { Log8.d(); return null; } return thumbnail; }
From source file:com.keylesspalace.tusky.activity.ComposeActivity.java
private void pickMedia(Uri uri, long mediaSize) { ContentResolver contentResolver = getContentResolver(); if (mediaSize == MEDIA_SIZE_UNKNOWN) { displayTransientError(R.string.error_media_upload_opening); return;// w w w .ja va 2s . c om } String mimeType = contentResolver.getType(uri); if (mimeType != null) { String topLevelType = mimeType.substring(0, mimeType.indexOf('/')); switch (topLevelType) { case "video": { if (mediaSize > STATUS_MEDIA_SIZE_LIMIT) { displayTransientError(R.string.error_media_upload_size); return; } if (mediaQueued.size() > 0 && mediaQueued.get(0).type == QueuedMedia.Type.IMAGE) { displayTransientError(R.string.error_media_upload_image_or_video); return; } MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(this, uri); Bitmap source = retriever.getFrameAtTime(); Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, 128, 128); source.recycle(); addMediaToQueue(QueuedMedia.Type.VIDEO, bitmap, uri, mediaSize); break; } case "image": { InputStream stream; try { stream = contentResolver.openInputStream(uri); } catch (FileNotFoundException e) { displayTransientError(R.string.error_media_upload_opening); return; } Bitmap source = BitmapFactory.decodeStream(stream); Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, 128, 128); source.recycle(); try { if (stream != null) { stream.close(); } } catch (IOException e) { bitmap.recycle(); displayTransientError(R.string.error_media_upload_opening); return; } addMediaToQueue(QueuedMedia.Type.IMAGE, bitmap, uri, mediaSize); break; } default: { displayTransientError(R.string.error_media_upload_type); break; } } } else { displayTransientError(R.string.error_media_upload_type); } }
From source file:com.fa.mastodon.activity.ComposeActivity.java
private void pickMedia(Uri uri, long mediaSize) { ContentResolver contentResolver = getContentResolver(); if (mediaSize == MEDIA_SIZE_UNKNOWN) { displayTransientError(R.string.error_media_upload_opening); return;//from ww w .ja va 2s. c om } String mimeType = contentResolver.getType(uri); if (mimeType != null) { String topLevelType = mimeType.substring(0, mimeType.indexOf('/')); switch (topLevelType) { case "video": { if (mediaSize > STATUS_MEDIA_SIZE_LIMIT) { displayTransientError(R.string.error_media_upload_size); return; } if (mediaQueued.size() > 0 && mediaQueued.get(0).type == QueuedMedia.Type.IMAGE) { displayTransientError(R.string.error_media_upload_image_or_video); return; } MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(this, uri); Bitmap source = retriever.getFrameAtTime(); Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, THUMBNAIL_SIZE, THUMBNAIL_SIZE); source.recycle(); addMediaToQueue(QueuedMedia.Type.VIDEO, bitmap, uri, mediaSize); break; } case "image": { InputStream stream; try { stream = contentResolver.openInputStream(uri); } catch (FileNotFoundException e) { displayTransientError(R.string.error_media_upload_opening); return; } Bitmap source = BitmapFactory.decodeStream(stream); Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, THUMBNAIL_SIZE, THUMBNAIL_SIZE); source.recycle(); try { if (stream != null) { stream.close(); } } catch (IOException e) { bitmap.recycle(); displayTransientError(R.string.error_media_upload_opening); return; } addMediaToQueue(QueuedMedia.Type.IMAGE, bitmap, uri, mediaSize); break; } default: { displayTransientError(R.string.error_media_upload_type); break; } } } else { displayTransientError(R.string.error_media_upload_type); } }