Search in sources :

Example 36 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project react-native-android-video-editor by RZulfikri.

the class VideoSurfaceView method setSource.

public void setSource(String uri) {
    videoUri = uri;
    try {
        mMediaPlayer.setDataSource(uri);
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        retriever.setDataSource(uri);
        videoHeight = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
        videoWidth = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
        rotation = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION));
        if (videoWidth > 0 && videoHeight > 0) {
            setDimension();
        }
        videoDuration = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
        WritableMap event = Arguments.createMap();
        event.putInt(Events.VIDEO_DURATION, videoDuration);
        eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_VIDEO_DURATION.toString(), event);
        retriever.release();
        retriever = null;
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) MediaMetadataRetriever(android.media.MediaMetadataRetriever) IOException(java.io.IOException)

Example 37 with MediaMetadataRetriever

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

the class ExternalMedia method loadMetadata.

@Override
public void loadMetadata() throws PlayableException {
    MediaMetadataRetriever mmr = new MediaMetadataRetriever();
    try {
        mmr.setDataSource(source);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        throw new PlayableException("IllegalArgumentException when setting up MediaMetadataReceiver");
    } catch (RuntimeException e) {
        // http://code.google.com/p/android/issues/detail?id=39770
        e.printStackTrace();
        throw new PlayableException("RuntimeException when setting up MediaMetadataRetriever");
    }
    episodeTitle = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
    feedTitle = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
    try {
        duration = Integer.parseInt(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
    } catch (NumberFormatException e) {
        e.printStackTrace();
        throw new PlayableException("NumberFormatException when reading duration of media file");
    }
    ChapterUtils.loadChaptersFromFileUrl(this);
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 38 with MediaMetadataRetriever

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

the class AudioCoverFetcher method loadData.

@Override
public InputStream loadData(Priority priority) throws Exception {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setDataSource(path);
        byte[] picture = retriever.getEmbeddedPicture();
        if (picture != null) {
            return new ByteArrayInputStream(picture);
        }
    } finally {
        retriever.release();
    }
    throw new IOException("Loading embedded cover did not work");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MediaMetadataRetriever(android.media.MediaMetadataRetriever) IOException(java.io.IOException)

Example 39 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 40 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)

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