title: MediaMetadataRetriever returns null but fine with MediaStore
body: <p>I am a newbie in developing android apps.<br>
  I'm developing a music player and would like to get song name, artist, album name, album art from the metadata of audio files.<br>
  I have used <code>MediaMetadataRetriever</code> but it is slow when there are 800+ songs and returns null for some files while other music players can retrieve those information.</p>
  
  <p>Then I use <code>MediaStore.Audio.Media.EXTERNAL_CONTENT_URI</code> to get song name, artist, album name and <code>MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI</code> to get the album art.</p>
  
  <p>Is there any uri to get (song name, artist, album name, album art) at the same time?<br>
  As I need to create a song object in my program.</p>
  
  <p>Below is my code, but it is very slow as it asks for album art for each song.</p>
  
  <pre><code>    public ArrayList&lt;Songs&gt; getPlayList(Context c) {
  
      String[] TRACK_PROJ = {
              MediaStore.Audio.AudioColumns.ARTIST,
              MediaStore.MediaColumns.TITLE,
              MediaStore.Audio.AudioColumns.ALBUM,
              MediaStore.Audio.AudioColumns.YEAR,
              MediaStore.MediaColumns.DATA
      };
      Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
      Cursor cursor = c.getContentResolver().query(uri, TRACK_PROJ, null, null, null);
  
      int count;
  
      if (cursor != null) {
          count = cursor.getCount();
          if (count &gt; 0) {
              cursor.moveToFirst();
              do {
                  Songs song;
                  String artist = cursor.getString(cursor.getColumnIndex(TRACK_PROJ[0]));
                  String title = cursor.getString(cursor.getColumnIndex(TRACK_PROJ[1]));
                  String album = cursor.getString(cursor.getColumnIndex(TRACK_PROJ[2]));
                  String year = cursor.getString(cursor.getColumnIndex(TRACK_PROJ[3]));
                  String path = cursor.getString(cursor.getColumnIndex(TRACK_PROJ[4]));
                  if (path.toLowerCase().contains(MEDIA_PATH.toLowerCase())) {
                      song = new Songs(artist, title, album, year, path);
                      songsList.add(song);
                  }
              } while (cursor.moveToNext());
          }
          cursor.close();
      }
  
      for (Songs aSongsList : songsList) {
  
          String[] ALBUM_PROJ = {MediaStore.Audio.Albums.ALBUM_ART};
          String selection = MediaStore.Audio.Albums.ALBUM + "=?";
          String[] values = new String[]{aSongsList.getAlbum()};
          Cursor cur = c.getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, ALBUM_PROJ, selection, values, null);
          int cnt;
          if (cur != null) {
              cnt = cur.getCount();
              if (cnt &gt; 0) {
                  cur.moveToFirst();
                  do {
                      String art = cur.getString(cur.getColumnIndex(ALBUM_PROJ[0]));
                      if (art != null)
                          aSongsList.setAlbumArt(art);
                  } while (cur.moveToNext());
                  cur.close();
              }
          }
      }
  
      return songsList;
  }
  </code></pre>
  
  <p>EDIT: (Code of using <code>MediaMetadataRetriever</code>)</p>
  
  <pre><code>    private Songs getMetadata (File file){
      String artist, title, album, path;
      MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
      metaRetriever.setDataSource(file.getPath());
  
      try {
  
          artist = metaRetriever
                  .extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
  
          album = metaRetriever
                  .extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
  
          path = file.getPath();
  
          title = metaRetriever
                  .extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
  
      } catch (Exception e) {
          artist = "Unknown";
          title = "Unknown";
          album = "Unknown";
          path = "Unknown";
      }
  </code></pre>
  
  <p>Thanks a lot!!!</p>