Search in sources :

Example 91 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project JamsMusicPlayer by psaravan.

the class ByteStreamBitmapHunter method decodeAsset.

Bitmap decodeAsset(String filePath) throws IOException {
    final BitmapFactory.Options options = createBitmapOptions(data);
    byte[] imageData = null;
    if (requiresInSampleSize(options)) {
        calculateInSampleSize(data.targetWidth, data.targetHeight, options);
    }
    try {
        MediaMetadataRetriever mmdr = new MediaMetadataRetriever();
        mmdr.setDataSource(filePath);
        imageData = mmdr.getEmbeddedPicture();
    } catch (Exception e) {
        return null;
    }
    ByteArrayInputStream is = new ByteArrayInputStream(imageData);
    try {
        return BitmapFactory.decodeStream(is, null, options);
    } finally {
        Utils.closeQuietly(is);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MediaMetadataRetriever(android.media.MediaMetadataRetriever) BitmapFactory(android.graphics.BitmapFactory) IOException(java.io.IOException)

Example 92 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project chromeview by pwnall.

the class MediaResourceGetter method extractMediaMetadata.

@CalledByNative
private static MediaMetadata extractMediaMetadata(Context context, String url, String cookies) {
    int durationInMilliseconds = 0;
    int width = 0;
    int height = 0;
    boolean success = false;
    // TODO(qinmin): use ConnectionTypeObserver to listen to the network type change.
    ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (mConnectivityManager != null) {
        NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
        if (info == null) {
            return new MediaMetadata(durationInMilliseconds, width, height, success);
        }
        switch(info.getType()) {
            case ConnectivityManager.TYPE_ETHERNET:
            case ConnectivityManager.TYPE_WIFI:
                break;
            case ConnectivityManager.TYPE_WIMAX:
            case ConnectivityManager.TYPE_MOBILE:
            default:
                return new MediaMetadata(durationInMilliseconds, width, height, success);
        }
    }
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        Uri uri = Uri.parse(url);
        String scheme = uri.getScheme();
        if (scheme == null || scheme.equals("file")) {
            File file = new File(uri.getPath());
            String path = file.getAbsolutePath();
            if (file.exists() && (path.startsWith("/mnt/sdcard/") || path.startsWith("/sdcard/") || path.startsWith(PathUtils.getExternalStorageDirectory()))) {
                retriever.setDataSource(path);
            } else {
                Log.e(TAG, "Unable to read file: " + url);
                return new MediaMetadata(durationInMilliseconds, width, height, success);
            }
        } else {
            HashMap<String, String> headersMap = new HashMap<String, String>();
            if (!TextUtils.isEmpty(cookies)) {
                headersMap.put("Cookie", cookies);
            }
            retriever.setDataSource(url, headersMap);
        }
        durationInMilliseconds = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
        width = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
        height = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
        success = true;
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "Invalid url: " + e);
    } catch (RuntimeException e) {
        Log.e(TAG, "Invalid url: " + e);
    }
    return new MediaMetadata(durationInMilliseconds, width, height, success);
}
Also used : NetworkInfo(android.net.NetworkInfo) HashMap(java.util.HashMap) ConnectivityManager(android.net.ConnectivityManager) Uri(android.net.Uri) MediaMetadataRetriever(android.media.MediaMetadataRetriever) File(java.io.File) CalledByNative(org.chromium.base.CalledByNative)

Example 93 with MediaMetadataRetriever

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

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

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

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

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

the class VideoTrim method getVideoInfo.

//    public void setMaxTrimDuration(int maxTrimDuration){
//        this.maxTrimDuration = maxTrimDuration;
//    }
/**
     * Function to get Video Detail, used to get video Duration and Set Video Player Max Duration
     */
private void getVideoInfo(String source) {
    MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
    mediaMetadataRetriever.setDataSource(source);
    duration = Integer.parseInt(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
    if (duration / 60000 >= 10) {
        maxDuration = 600000;
        // videoPlayerControl.setEndPos(maxDuration);
        WritableMap event = Arguments.createMap();
        event.putInt(Events.END_POS, maxDuration);
        eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_END_POS.toString(), event);
    } else {
        maxDuration = duration;
        rangeSeekEndPos = maxDuration;
        // videoPlayerControl.setEndPos(maxDuration);
        WritableMap event = Arguments.createMap();
        event.putInt(Events.END_POS, maxDuration);
        eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_END_POS.toString(), event);
    }
    //         Log.e("DEBUG", " "+duration+" "+maxDuration+" "+((minTrimDuration * 100f) / (float)maxDuration));
    seekbar.setRangeMin((minTrimDuration * 100f) / (float) maxDuration);
    mediaMetadataRetriever.release();
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) 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