Search in sources :

Example 41 with MediaMetadataRetriever

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

the class MediaMetadataTest method validateMetatData.

private static void validateMetatData(int fileIndex, String[][] meta_data_file) {
    Log.v(TAG, "filePath = " + meta_data_file[fileIndex][0]);
    if ((meta_data_file[fileIndex][0].endsWith("wma") && !MediaProfileReader.getWMAEnable()) || (meta_data_file[fileIndex][0].endsWith("wmv") && !MediaProfileReader.getWMVEnable())) {
        return;
    }
    String value = null;
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setDataSource(meta_data_file[fileIndex][0]);
    } catch (Exception e) {
        Log.v(TAG, "Failed: " + meta_data_file[fileIndex][0] + " " + e.toString());
        //Set the test case failure whenever it failed to setDataSource
        assertTrue("Failed to setDataSource ", false);
    }
    //METADATA_KEY_CD_TRACK_NUMBER should return the TCRK value
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER);
    Log.v(TAG, "CD_TRACK_NUMBER : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.CD_TRACK.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
    Log.v(TAG, "Album : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.ALBUM.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
    Log.v(TAG, "Artist : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.ARTIST.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_AUTHOR);
    Log.v(TAG, "Author : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.AUTHOR.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_COMPOSER);
    Log.v(TAG, "Composer : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.COMPOSER.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE);
    Log.v(TAG, "Date : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.DATE.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);
    Log.v(TAG, "Genre : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.GENRE.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
    Log.v(TAG, "Title : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.TITLE.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
    Log.v(TAG, "Year : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.YEAR.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
    Log.v(TAG, "Expected = " + meta_data_file[fileIndex][meta.DURATION.ordinal()] + "reult = " + value);
    // Only require that the returned duration is within 100ms of the expected
    // one as PV and stagefright differ slightly in their implementation.
    assertTrue(TAG, Math.abs(Integer.parseInt(meta_data_file[fileIndex][meta.DURATION.ordinal()]) - Integer.parseInt(value)) < 100);
    //METADATA_KEY_NUM_TRACKS should return the total number of tracks in the media
    //include the video and audio
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS);
    Log.v(TAG, "Track : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.NUM_TRACKS.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_WRITER);
    Log.v(TAG, "Writer : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.WRITER.ordinal()], value);
    retriever.release();
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 42 with MediaMetadataRetriever

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

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)

Example 43 with MediaMetadataRetriever

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

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

use of android.media.MediaMetadataRetriever in project wire-android by wireapp.

the class AssetUtils method getVideoAssetDurationMilliSec.

public static long getVideoAssetDurationMilliSec(Context context, Uri uri) {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    retriever.setDataSource(context, uri);
    String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
    return Long.parseLong(time);
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 45 with MediaMetadataRetriever

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

the class FileBackend method getVideoDimensions.

private Dimensions getVideoDimensions(File file) throws NotAVideoFile {
    MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
    try {
        metadataRetriever.setDataSource(file.getAbsolutePath());
    } catch (Exception e) {
        throw new NotAVideoFile();
    }
    String hasVideo = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_HAS_VIDEO);
    if (hasVideo == null) {
        throw new NotAVideoFile();
    }
    int rotation = extractRotationFromMediaRetriever(metadataRetriever);
    boolean rotated = rotation == 90 || rotation == 270;
    int height;
    try {
        String h = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
        height = Integer.parseInt(h);
    } catch (Exception e) {
        height = -1;
    }
    int width;
    try {
        String w = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
        width = Integer.parseInt(w);
    } catch (Exception e) {
        width = -1;
    }
    metadataRetriever.release();
    Log.d(Config.LOGTAG, "extracted video dims " + width + "x" + height);
    return rotated ? new Dimensions(width, height) : new Dimensions(height, width);
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever) FileWriterException(eu.siacs.conversations.utils.FileWriterException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) Paint(android.graphics.Paint)

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