public void getAlbumArt(){
final Uri albumArtUri = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
Cursor albumCursor = getContentResolver().query(albumArtUri, null, null, null, null);
if (albumCursor != null && albumCursor.moveToFirst()){
int album_Art = albumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM_ART);
do {
String albumArt = albumCursor.getString(album_Art);
QuerySongs querySongs = new QuerySongs(null, null, null, null, null, albumArt);
songList.add(querySongs);
}while(albumCursor.moveToNext());
albumCursor.close();
}
}
어댑터 클래스는피카소는 앨범 아트를로드 작동하지
나는 SD 카드에 음악에서 앨범 아트를 얻기에 문제가public void onBindViewHolder(SongHolder holder, final int position) {
//holder.tvIndex.setText(String.format(Locale.US, "%d", position));
holder.tvSongTitle.setText(songList.get(position).getTitle());
holder.tvArtistName.setText(songList.get(position).getArtist());
Picasso.with(context)
.load(Uri.parse("file://"+songList.get(position).getAlbumart()))
.error(R.drawable.no_album)
.into(holder.albumIv);
}
, 앨범을 얻을 수있는 가장 쉬운 방법은 무엇입니까 예술, 그리고 그것을 imageview에 표시? 내가 잘못하고있는 것에 대한 단서가 없다.이 포럼의 다른 게시물을 살펴 보았지만 아무 소용이 없지만 올바르게 수행하는 방법을 찾지 못했습니다.
감사합니다,
편집
public void getAlbumArt(){
final Uri albumArtUri = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
Cursor albumCursor = getContentResolver().query(albumArtUri, null, null, null, null);
if (albumCursor != null && albumCursor.moveToFirst()){
int albumart_Column = albumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM_ART);
do {
String albumArt = albumCursor.getString(albumart_Column);
QuerySongs querySongs = new QuerySongs(null, null, null, null, null, albumArt);
songList.add(querySongs);
}while(albumCursor.moveToNext());
albumCursor.close();
}
albumIv = findViewById(R.id.albumIv);
Picasso.with(context)
.load(albumArtUri)
.error(R.drawable.no_album)
.into(albumIv);
}
노래 생성자
package com.vince_mp3player.mp3player;
/**
* Created by Vincent on 12/11/2017.
*/
public class QuerySongs {
long id;
long albumid;
String data;
String title;
String artist;
String albumart;
public QuerySongs(Long songId, Long albumId, String songData, String
songName, String songArtist, String albumArt){
this.id = songId;
this.albumid = albumId;
this.data = songData;
this.title = songName;
this.artist = songArtist;
this.albumart = albumArt;
}
public Long getId(){
return id;
}
public long getAlbumid() { return albumid; }
public String getData(){
return data;
}
public String getTitle() {
return title;
}
public String getArtist() {
return artist;
}
public String getAlbumart() { return albumart; }
}
디스플레이 노래 클래스
public void getAlbumArt(){
final Uri albumArtUri = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
Cursor albumCursor = getContentResolver().query(albumArtUri, null, null, null, null);
if (albumCursor != null && albumCursor.moveToFirst()){
int albumart_Column = albumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM_ART);
do {
Uri albumArt = Uri.parse(albumCursor.getString(albumart_Column));
QuerySongs querySongs = new QuerySongs(null, null, null, null, null, albumArt);
songList.add(querySongs);
}while(albumCursor.moveToNext());
albumCursor.close();
}
}
SongAdapter
@Override
public void onBindViewHolder(SongHolder holder, final int position) {
//holder.tvIndex.setText(String.format(Locale.US, "%d", position));
holder.tvSongTitle.setText(songList.get(position).getTitle());
holder.tvArtistName.setText(songList.get(position).getArtist());
Picasso.with(context)
.load(Uri.parse(songList.get(songIndex).getAlbumart()))
.error(R.drawable.no_album)
.into(holder.albumIv);
}
편집 2
public void getSongs() {
final Uri songUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC + "!=0";
Cursor myCursor = getContentResolver().query(songUri, null, selection, null, null);
if (myCursor != null && myCursor.moveToFirst()) {
int id_Column = myCursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID);
int albumId_Column = myCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID);
int data_Column = myCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
int title_Column = myCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE);
int artist_Column = myCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST);
int album_Column = myCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM);
do {
Long songId = myCursor.getLong(id_Column);
Long albumId = myCursor.getLong(albumId_Column);
String songData = myCursor.getString(data_Column);
String songName = myCursor.getString(title_Column);
String songArtist = myCursor.getString(artist_Column);
String songAlbum = myCursor.getString(album_Column);
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri, albumId);
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), albumArtUri);
bitmap = Bitmap.createScaledBitmap(bitmap, 30, 30, true);
}catch (FileNotFoundException exception){
exception.printStackTrace();
bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.no_album);
}catch (Exception e){
e.printStackTrace();
}
QuerySongs querySongs = new QuerySongs(songId, albumId, songData, songName, songArtist, songAlbum);
songList.add(querySongs);
} while (myCursor.moveToNext());
myCursor.close();
}
}
'MediaSto re.Audio.Albums.EXTERNAL_CONTENT_URI'는 이미 예술이있는 URI입니다. 왜 Uri.parse ("file : //"'? –
songList.get (position) .getAlbumart() 만 필요합니까? – Vince
그 값이 무엇인지는 분명하지 않습니다. URI가 아닌 문자열입니다. https://stackoverflow.com/a/23681332/2308683 –