use of android.media.MediaMetadataRetriever in project XobotOS by xamarin.
the class ThumbnailUtils method createVideoThumbnail.
/**
* Create a video thumbnail for a video. May return null if the video is
* corrupt or the format is not supported.
*
* @param filePath the path of video file
* @param kind could be MINI_KIND or MICRO_KIND
*/
public static Bitmap createVideoThumbnail(String filePath, int kind) {
Bitmap bitmap = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(filePath);
bitmap = retriever.getFrameAtTime(-1);
} 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.
}
}
if (bitmap == null)
return null;
if (kind == Images.Thumbnails.MINI_KIND) {
// Scale down the bitmap if it's too large.
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int max = Math.max(width, height);
if (max > 512) {
float scale = 512f / max;
int w = Math.round(scale * width);
int h = Math.round(scale * height);
bitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
}
} else if (kind == Images.Thumbnails.MICRO_KIND) {
bitmap = extractThumbnail(bitmap, TARGET_SIZE_MICRO_THUMBNAIL, TARGET_SIZE_MICRO_THUMBNAIL, OPTIONS_RECYCLE_INPUT);
}
return bitmap;
}
use of android.media.MediaMetadataRetriever in project AntennaPod by AntennaPod.
the class FeedMedia method checkEmbeddedPicture.
public void checkEmbeddedPicture() {
if (!localFileAvailable()) {
hasEmbeddedPicture = Boolean.FALSE;
return;
}
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
try {
mmr.setDataSource(getLocalMediaUrl());
byte[] image = mmr.getEmbeddedPicture();
if (image != null) {
hasEmbeddedPicture = Boolean.TRUE;
} else {
hasEmbeddedPicture = Boolean.FALSE;
}
} catch (Exception e) {
e.printStackTrace();
hasEmbeddedPicture = Boolean.FALSE;
}
}
use of android.media.MediaMetadataRetriever in project android_packages_apps_Camera by CyanogenMod.
the class VideoCaptureIntentTest method verify.
// Verify result code, result data, and the duration.
private int verify(CameraActivity activity, Uri uri) throws Exception {
assertTrue(activity.isFinishing());
assertEquals(Activity.RESULT_OK, activity.getResultCode());
// Verify the video file
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(activity, uri);
String duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
assertNotNull(duration);
int durationValue = Integer.parseInt(duration);
Log.v(TAG, "Video duration is " + durationValue);
assertTrue(durationValue > 0);
return durationValue;
}
use of android.media.MediaMetadataRetriever in project android_frameworks_base by DirtyUnicorns.
the class ThumbnailUtils method createVideoThumbnail.
/**
* Create a video thumbnail for a video. May return null if the video is
* corrupt or the format is not supported.
*
* @param filePath the path of video file
* @param kind could be MINI_KIND or MICRO_KIND
*/
public static Bitmap createVideoThumbnail(String filePath, int kind) {
Bitmap bitmap = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(filePath);
bitmap = retriever.getFrameAtTime(-1);
} 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.
}
}
if (bitmap == null)
return null;
if (kind == Images.Thumbnails.MINI_KIND) {
// Scale down the bitmap if it's too large.
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int max = Math.max(width, height);
if (max > 512) {
float scale = 512f / max;
int w = Math.round(scale * width);
int h = Math.round(scale * height);
bitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
}
} else if (kind == Images.Thumbnails.MICRO_KIND) {
bitmap = extractThumbnail(bitmap, TARGET_SIZE_MICRO_THUMBNAIL, TARGET_SIZE_MICRO_THUMBNAIL, OPTIONS_RECYCLE_INPUT);
}
return bitmap;
}
use of android.media.MediaMetadataRetriever in project android_frameworks_base by AOSPA.
the class EffectsVideoCapture method verify.
// Verify result code, result data, and the duration.
private void verify(CameraEffectsRecordingSample activity, Uri uri) throws Exception {
assertNotNull(uri);
// Verify the video file
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(activity, uri);
String duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
assertNotNull(duration);
int durationValue = Integer.parseInt(duration);
Log.v(TAG, "Video duration is " + durationValue);
assertTrue(durationValue > 0);
}
Aggregations