Search in sources :

Example 76 with MediaMetadataRetriever

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

the class MediaMetadataRetrieverTest method testMetadataRetrieval.

@LargeTest
public static void testMetadataRetrieval() throws Exception {
    boolean supportWMA = MediaProfileReader.getWMAEnable();
    boolean supportWMV = MediaProfileReader.getWMVEnable();
    boolean hasFailed = false;
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    for (int i = 0, n = MediaNames.THUMBNAIL_METADATA_TEST_FILES.length; i < n; ++i) {
        try {
            Log.v(TAG, "File " + i + ": " + MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
            if ((MediaNames.THUMBNAIL_METADATA_TEST_FILES[i].endsWith(".wma") && !supportWMA) || (MediaNames.THUMBNAIL_METADATA_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.THUMBNAIL_METADATA_TEST_FILES[i]);
            extractAllSupportedMetadataValues(retriever);
        } catch (Exception e) {
            Log.e(TAG, "Fails to setDataSource for file " + MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
            hasFailed = true;
        }
        // Don't be evil
        Thread.yield();
    }
    retriever.release();
    assertTrue(!hasFailed);
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 77 with MediaMetadataRetriever

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

the class MediaDecoder method retrieveDefaultRotation.

@TargetApi(17)
private void retrieveDefaultRotation() {
    MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
    metadataRetriever.setDataSource(mContext, mUri);
    String rotationString = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
    mDefaultRotation = rotationString == null ? 0 : Integer.parseInt(rotationString);
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever) TargetApi(android.annotation.TargetApi)

Example 78 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project Conversations by siacs.

the class FileBackend method getVideoPreview.

private Bitmap getVideoPreview(File file, int size) {
    MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
    Bitmap frame;
    try {
        metadataRetriever.setDataSource(file.getAbsolutePath());
        frame = metadataRetriever.getFrameAtTime(0);
        metadataRetriever.release();
        frame = resize(frame, size);
    } catch (IllegalArgumentException | NullPointerException e) {
        frame = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
        frame.eraseColor(0xff000000);
    }
    drawOverlay(frame, R.drawable.play_video, 0.75f);
    return frame;
}
Also used : Bitmap(android.graphics.Bitmap) MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 79 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project Timber by naman14.

the class TimberUtils method getAlbumArtForFile.

public static String getAlbumArtForFile(String filePath) {
    MediaMetadataRetriever mmr = new MediaMetadataRetriever();
    mmr.setDataSource(filePath);
    return mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 80 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project WordPress-Android by wordpress-mobile.

the class MediaUtils method getVideoDurationMS.

public static long getVideoDurationMS(Context context, Uri videoUri) {
    if (context == null || videoUri == null) {
        AppLog.e(AppLog.T.MEDIA, "context and videoUri can't be null.");
        return 0L;
    }
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setDataSource(context, videoUri);
    } catch (IllegalArgumentException | SecurityException e) {
        AppLog.e(AppLog.T.MEDIA, "Can't read duration of the video.", e);
        return 0L;
    } catch (RuntimeException e) {
        // Ref: https://github.com/wordpress-mobile/WordPress-Android/issues/5431
        AppLog.e(AppLog.T.MEDIA, "Can't read duration of the video due to a Runtime Exception happened setting the datasource", e);
        return 0L;
    }
    String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
    if (time == null) {
        return 0L;
    }
    return Long.parseLong(time);
}
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