Search in sources :

Example 11 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project MusicDNA by harjot-oberai.

the class CustomAdapter method getBitmap.

public Bitmap getBitmap(String url) {
    try {
        android.media.MediaMetadataRetriever mmr = new MediaMetadataRetriever();
        mmr.setDataSource(url);
        Bitmap bitmap = null;
        byte[] data = mmr.getEmbeddedPicture();
        if (data != null) {
            bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
            return bitmap;
        } else {
            return null;
        }
    } catch (Throwable ex) {
        ex.printStackTrace();
    }
    return null;
}
Also used : Bitmap(android.graphics.Bitmap) MediaMetadataRetriever(android.media.MediaMetadataRetriever) MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 12 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project MusicDNA by harjot-oberai.

the class ViewAlbumFragment method getBitmap.

public Bitmap getBitmap(String url) {
    android.media.MediaMetadataRetriever mmr = new MediaMetadataRetriever();
    mmr.setDataSource(url);
    Bitmap bitmap = null;
    byte[] data = mmr.getEmbeddedPicture();
    if (data != null) {
        bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
        return bitmap;
    } else {
        return null;
    }
}
Also used : Bitmap(android.graphics.Bitmap) MediaMetadataRetriever(android.media.MediaMetadataRetriever) MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 13 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project MusicDNA by harjot-oberai.

the class LocalTrackRecyclerAdapter method getAlbumArt.

public static Bitmap getAlbumArt(String path) {
    android.media.MediaMetadataRetriever mmr = new MediaMetadataRetriever();
    mmr.setDataSource(path);
    Bitmap bitmap = null;
    byte[] data = mmr.getEmbeddedPicture();
    if (data != null) {
        bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
        return bitmap;
    } else {
        return null;
    }
}
Also used : Bitmap(android.graphics.Bitmap) MediaMetadataRetriever(android.media.MediaMetadataRetriever) MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 14 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 15 with MediaMetadataRetriever

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

the class AsyncPlayFolderRecursiveTask method extractFileMetadata.

//Extracts specific ID3 metadata from an audio file and returns them in an ArrayList.
public static ArrayList<Object> extractFileMetadata(String filePath) {
    ArrayList<Object> metadata = new ArrayList<Object>();
    MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
    mediaMetadataRetriever.setDataSource(filePath);
    metadata.add(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE));
    metadata.add(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST));
    metadata.add(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM));
    metadata.add(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
    metadata.add(mediaMetadataRetriever.getEmbeddedPicture());
    return metadata;
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever) ArrayList(java.util.ArrayList)

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