Search in sources :

Example 16 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project platform_frameworks_base by android.

the class MediaMetadataRetrieverTest method testBasicNormalMethodCallSequence.

// If the specified call order and valid media file is used, no exception
// should be thrown.
@MediumTest
public static void testBasicNormalMethodCallSequence() throws Exception {
    boolean hasFailed = false;
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setDataSource(MediaNames.TEST_PATH_1);
        Bitmap bitmap = retriever.getFrameAtTime(-1);
        assertTrue(bitmap != null);
        try {
            java.io.OutputStream stream = new FileOutputStream("/sdcard/thumbnailout.jpg");
            bitmap.compress(Bitmap.CompressFormat.JPEG, 75, stream);
            stream.close();
        } catch (Exception e) {
            throw new Exception("Fails to convert the bitmap to a JPEG file for " + MediaNames.TEST_PATH_1, e);
        }
        extractAllSupportedMetadataValues(retriever);
    } catch (Exception e) {
        Log.e(TAG, "Fails to setDataSource for " + MediaNames.TEST_PATH_1, e);
        hasFailed = true;
    }
    retriever.release();
    assertTrue(!hasFailed);
}
Also used : Bitmap(android.graphics.Bitmap) MediaMetadataRetriever(android.media.MediaMetadataRetriever) FileOutputStream(java.io.FileOutputStream)

Example 17 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project platform_frameworks_base by android.

the class MediaMetadataRetrieverTest method testGetEmbeddedPicture.

// Test album art extraction.
@MediumTest
public static void testGetEmbeddedPicture() throws Exception {
    Log.v(TAG, "testGetEmbeddedPicture starts.");
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    boolean supportWMA = MediaProfileReader.getWMAEnable();
    boolean hasFailed = false;
    boolean supportWMV = MediaProfileReader.getWMVEnable();
    for (int i = 0, n = MediaNames.ALBUMART_TEST_FILES.length; i < n; ++i) {
        try {
            Log.v(TAG, "File " + i + ": " + MediaNames.ALBUMART_TEST_FILES[i]);
            if ((MediaNames.ALBUMART_TEST_FILES[i].endsWith(".wma") && !supportWMA) || (MediaNames.ALBUMART_TEST_FILES[i].endsWith(".wmv") && !supportWMV)) {
                Log.v(TAG, "windows media is not supported and thus we will skip the test for this file");
                continue;
            }
            retriever.setDataSource(MediaNames.ALBUMART_TEST_FILES[i]);
            byte[] albumArt = retriever.getEmbeddedPicture();
            // known result.
            if (albumArt == null) {
                // Do we have expect in JUnit?
                Log.e(TAG, "Fails to get embedded picture for " + MediaNames.ALBUMART_TEST_FILES[i]);
                hasFailed = true;
            }
        } catch (Exception e) {
            Log.e(TAG, "Fails to setDataSource for " + MediaNames.ALBUMART_TEST_FILES[i]);
            hasFailed = true;
        }
        // Don't be evil
        Thread.yield();
    }
    retriever.release();
    Log.v(TAG, "testGetEmbeddedPicture completes.");
    assertTrue(!hasFailed);
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 18 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project platform_frameworks_base by android.

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 19 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project platform_frameworks_base by android.

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 20 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project ion by koush.

the class VideoLoader method createVideoThumbnail.

@TargetApi(Build.VERSION_CODES.GINGERBREAD_MR1)
public static Bitmap createVideoThumbnail(String filePath) throws Exception {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    retriever.setDataSource(filePath);
    try {
        return retriever.getFrameAtTime();
    } finally {
        try {
            retriever.release();
        } catch (Exception ignored) {
        }
    }
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever) TargetApi(android.annotation.TargetApi)

Aggregations

MediaMetadataRetriever (android.media.MediaMetadataRetriever)105 Bitmap (android.graphics.Bitmap)40 FileOutputStream (java.io.FileOutputStream)15 IOException (java.io.IOException)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