Search in sources :

Example 81 with MediaMetadataRetriever

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;
}
Also used : Bitmap(android.graphics.Bitmap) MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 82 with MediaMetadataRetriever

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;
    }
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 83 with MediaMetadataRetriever

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;
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 84 with MediaMetadataRetriever

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;
}
Also used : Bitmap(android.graphics.Bitmap) MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 85 with MediaMetadataRetriever

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);
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Aggregations

MediaMetadataRetriever (android.media.MediaMetadataRetriever)106 Bitmap (android.graphics.Bitmap)40 IOException (java.io.IOException)16 FileOutputStream (java.io.FileOutputStream)15 BitmapFactory (android.graphics.BitmapFactory)7 TargetApi (android.annotation.TargetApi)5 File (java.io.File)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Intent (android.content.Intent)2 Paint (android.graphics.Paint)2 MediaItem (android.media.videoeditor.MediaItem)2 WritableMap (com.facebook.react.bridge.WritableMap)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 SuppressLint (android.annotation.SuppressLint)1 Notification (android.app.Notification)1 PendingIntent (android.app.PendingIntent)1 ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1