Search in sources :

Example 86 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project android_frameworks_base by AOSPA.

the class MediaMetadataRetrieverTest method testSetDataSource.

// Test setDataSource()
@MediumTest
public static void testSetDataSource() {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    boolean hasFailed = false;
    // Null pointer argument
    try {
        String path = null;
        retriever.setDataSource(path);
        Log.e(TAG, "IllegalArgumentException failed to be thrown.");
        hasFailed = true;
    } catch (Exception e) {
        if (!(e instanceof IllegalArgumentException)) {
            Log.e(TAG, "Expected a IllegalArgumentException, but got a different exception");
            hasFailed = true;
        }
    }
    // Use mem:// path
    try {
        retriever.setDataSource(MediaNames.TEST_PATH_5);
        Log.e(TAG, "IllegalArgumentException failed to be thrown.");
        hasFailed = true;
    } catch (Exception e) {
        if (!(e instanceof IllegalArgumentException)) {
            Log.e(TAG, "Expected a IllegalArgumentException, but got a different exception");
            hasFailed = true;
        }
    }
    // The pathname does not correspond to any existing file
    try {
        retriever.setDataSource(MediaNames.TEST_PATH_4);
        Log.e(TAG, "RuntimeException failed to be thrown.");
        hasFailed = true;
    } catch (Exception e) {
        if (!(e instanceof RuntimeException)) {
            Log.e(TAG, "Expected a RuntimeException, but got a different exception");
            hasFailed = true;
        }
    }
    // is not a valid media file
    try {
        retriever.setDataSource(MediaNames.TEST_PATH_3);
        Log.e(TAG, "RuntimeException failed to be thrown.");
        hasFailed = true;
    } catch (Exception e) {
        if (!(e instanceof RuntimeException)) {
            Log.e(TAG, "Expected a RuntimeException, but got a different exception");
            hasFailed = true;
        }
    }
    retriever.release();
    assertTrue(!hasFailed);
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 87 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project android_frameworks_base by AOSPA.

the class MediaMetadataRetrieverTest method testBasicAbnormalMethodCallSequence.

// If setDataSource() has not been called, both getFrameAtTime() and extractMetadata() must
// return null.
@MediumTest
public static void testBasicAbnormalMethodCallSequence() {
    boolean hasFailed = false;
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    if (retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM) != null) {
        Log.e(TAG, "No album metadata expected, but is available");
        hasFailed = true;
    }
    if (retriever.getFrameAtTime(-1) != null) {
        Log.e(TAG, "No frame expected, but is available");
        hasFailed = true;
    }
    assertTrue(!hasFailed);
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 88 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project android_frameworks_base by AOSPA.

the class MediaRecorderTest method validateMetadata.

private boolean validateMetadata(String filePath, int captureRate) {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    retriever.setDataSource(filePath);
    // verify capture rate meta key is present and correct
    String captureFps = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CAPTURE_FRAMERATE);
    if (captureFps == null) {
        Log.d(TAG, "METADATA_KEY_CAPTURE_FRAMERATE is missing");
        return false;
    }
    if (Math.abs(Float.parseFloat(captureFps) - captureRate) > 0.001) {
        Log.d(TAG, "METADATA_KEY_CAPTURE_FRAMERATE is incorrect: " + captureFps + "vs. " + captureRate);
        return false;
    }
    // verify other meta keys here if necessary
    return true;
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 89 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project android_frameworks_base by AOSPA.

the class CodecTest method getThumbnail.

//Test for mediaMeta Data Thumbnail
public static boolean getThumbnail(String filePath, String goldenPath) {
    Log.v(TAG, "getThumbnail - " + filePath);
    int goldenHeight = 0;
    int goldenWidth = 0;
    int outputWidth = 0;
    int outputHeight = 0;
    //This test is only for the short media file
    try {
        BitmapFactory mBitmapFactory = new BitmapFactory();
        MediaMetadataRetriever mMediaMetadataRetriever = new MediaMetadataRetriever();
        try {
            mMediaMetadataRetriever.setDataSource(filePath);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        Bitmap outThumbnail = mMediaMetadataRetriever.getFrameAtTime(-1);
        //Verify the thumbnail
        Bitmap goldenBitmap = mBitmapFactory.decodeFile(goldenPath);
        outputWidth = outThumbnail.getWidth();
        outputHeight = outThumbnail.getHeight();
        goldenHeight = goldenBitmap.getHeight();
        goldenWidth = goldenBitmap.getWidth();
        //check the image dimension
        if ((outputWidth != goldenWidth) || (outputHeight != goldenHeight))
            return false;
        // Check half line of pixel
        int x = goldenHeight / 2;
        for (int j = 1; j < goldenWidth / 2; j++) {
            if (goldenBitmap.getPixel(x, j) != outThumbnail.getPixel(x, j)) {
                Log.v(TAG, "pixel = " + goldenBitmap.getPixel(x, j));
                return false;
            }
        }
    } catch (Exception e) {
        Log.v(TAG, e.toString());
        return false;
    }
    return true;
}
Also used : Bitmap(android.graphics.Bitmap) MediaMetadataRetriever(android.media.MediaMetadataRetriever) BitmapFactory(android.graphics.BitmapFactory) IOException(java.io.IOException)

Example 90 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project android_frameworks_base by AOSPA.

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)

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