在MediaStore.Audio.Albums.ALBUM_ART中获取专辑Art Path null

时间:2017-09-03 04:53:00

标签: android

我试图在我的代码中获取所有专辑的专辑封面,但我从下面的代码中得到Null: -

 private void listAlbum() {
        String where = null;

        final Uri uri = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
        final String _id = MediaStore.Audio.Albums._ID;
        final String album_name = MediaStore.Audio.Albums.ALBUM;
        final String artist = MediaStore.Audio.Albums.ARTIST;
        final String albumart = MediaStore.Audio.Albums.ALBUM_ART;
        final String tracks = MediaStore.Audio.Albums.NUMBER_OF_SONGS;

        final String[] columns = { _id, album_name, artist, albumart, tracks};
        Cursor cursor = getActivity().getContentResolver().query(uri, columns, where, null, album_name+" ASC");

        if(cursor!=null && cursor.moveToFirst()){

            do {

                long id = cursor.getLong(cursor.getColumnIndex(_id));
                String name = cursor.getString(cursor.getColumnIndex(album_name));
                String artist2 = cursor.getString(cursor.getColumnIndex(artist));
                String artPath = cursor.getString(cursor.getColumnIndex(albumart));
                int nr =Integer.parseInt(cursor.getString(cursor.getColumnIndex(tracks)));

                albumName.add(name);
                albumTrack.add(nr+" Songs ");
                albumArt.add(artPath);
                albumArtist.add(artist2);
                albumId.add(id);
                Log.d("EasysPlay","Art Url "+artPath);

            } while (cursor.moveToNext());
        }

        assert cursor != null;
        cursor.close();
    }

我不知道此代码中的问题是什么。 我记录它并使专辑封面无效。 有人知道这段代码的问题是什么:)

0 个答案:

没有答案