Search in sources :

Example 26 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project XobotOS by xamarin.

the class VideoEditorImpl method generateProjectThumbnail.

/*
     * Generate the project thumbnail
     */
private void generateProjectThumbnail() {
    /*
         * If a thumbnail already exists, then delete it first
         */
    if ((new File(mProjectPath + "/" + THUMBNAIL_FILENAME)).exists()) {
        (new File(mProjectPath + "/" + THUMBNAIL_FILENAME)).delete();
    }
    /*
         * Generate a new thumbnail for the project from first media Item
         */
    if (mMediaItems.size() > 0) {
        MediaItem mI = mMediaItems.get(0);
        /*
             * Keep aspect ratio of the image
             */
        int height = 480;
        int width = mI.getWidth() * height / mI.getHeight();
        Bitmap projectBitmap = null;
        String filename = mI.getFilename();
        if (mI instanceof MediaVideoItem) {
            MediaMetadataRetriever retriever = new MediaMetadataRetriever();
            retriever.setDataSource(filename);
            Bitmap bitmap = retriever.getFrameAtTime();
            retriever.release();
            retriever = null;
            if (bitmap == null) {
                String msg = "Thumbnail extraction from " + filename + " failed";
                throw new IllegalArgumentException(msg);
            }
            // Resize the thumbnail to the target size
            projectBitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
        } else {
            try {
                projectBitmap = mI.getThumbnail(width, height, 500);
            } catch (IllegalArgumentException e) {
                String msg = "Project thumbnail extraction from " + filename + " failed";
                throw new IllegalArgumentException(msg);
            } catch (IOException e) {
                String msg = "IO Error creating project thumbnail";
                throw new IllegalArgumentException(msg);
            }
        }
        try {
            FileOutputStream stream = new FileOutputStream(mProjectPath + "/" + THUMBNAIL_FILENAME);
            projectBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            stream.flush();
            stream.close();
        } catch (IOException e) {
            throw new IllegalArgumentException("Error creating project thumbnail");
        } finally {
            projectBitmap.recycle();
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) MediaItem(android.media.videoeditor.MediaItem) MediaMetadataRetriever(android.media.MediaMetadataRetriever) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 27 with MediaMetadataRetriever

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

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 28 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 29 with MediaMetadataRetriever

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

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 30 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)

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