3

Is it possible to retrieve bitmap( Album art ) of mp3 file from it's file path or file input stream. Like using BitmapFactory API or some other API.

Moses
  • 333
  • 1
  • 6
  • 19
  • Have you checked this. http://stackoverflow.com/questions/13592709/retrieve-album-art-using-ffmpeg – dishooom May 21 '15 at 06:24
  • It is seems good. Don't we have any android API? – Moses May 21 '15 at 06:28
  • I am pretty sure there is none. In one of my prior projects i had to drill down in FFmpeg for something similar. – dishooom May 21 '15 at 06:30
  • Yup.. thanks you have saved my time. Please write it in answer panel. I will mark it as right answer. so that it will be helpful to others – Moses May 21 '15 at 06:43

3 Answers3

5

Yes, it is possible to get mp3 cover art.

MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(mPath);
InputStream inputStream = null;
if (mmr.getEmbeddedPicture() != null) {
    inputStream = new ByteArrayInputStream(mmr.getEmbeddedPicture());
 }
mmr.release();

bitmap = BitmapFactory.decodeStream(inputStream);
Tanay Mondal
  • 147
  • 2
  • 9
4

Using the following method you can get the album art uri of an image file.

public Uri getArtUriFromMusicFile(File file) {
        final Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        final String[] cursor_cols = { MediaStore.Audio.Media.ALBUM_ID };

        final String where = MediaStore.Audio.Media.IS_MUSIC + "=1 AND " + MediaStore.Audio.Media.DATA + " = '"
                + file.getAbsolutePath() + "'";
        final Cursor cursor = context.getContentResolver().query(uri, cursor_cols, where, null, null);
        Log.d(TAG, "Cursor count:" + cursor.getCount());
        /*
         * If the cusor count is greater than 0 then parse the data and get the art id.
         */
        if (cursor != null && cursor.getCount() > 0) {
            cursor.moveToFirst();
            Long albumId = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID));

            Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
            Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri, albumId);
            cursor.close();
            return albumArtUri;
        }
        return Uri.EMPTY;
    }
Kartheek
  • 7,104
  • 3
  • 30
  • 44
  • Kartheek.. i have my files in network. So i can't use your code – Moses May 21 '15 at 06:47
  • thanks, but doesn't work for all files: `android.database.sqlite.SQLiteException: near "s": syntax error (code 1): , while compiling: SELECT album_id FROM audio WHERE (is_music=1 AND _data = '/storage/emulated/0/Music/Marked/2013 Gordon & Doyle vs Scooter- Let's Go Biz (Tr-Meet & Yuliana Mash-up).mp3')` – user924 Sep 17 '17 at 10:36
  • I guess it's because of `'` symbol in filename, do you know how to fix it? – user924 Sep 17 '17 at 10:38
  • this could help `path = path.replaceAll("'", "''");` – user924 Sep 17 '17 at 10:40
0

To extract album art from an mp3 file, there is no direct API available in Android as of now. You need to extract it via FFmpeg for the same.

dishooom
  • 498
  • 4
  • 9