如何从歌曲文件中获取专辑封面(即图像文件),我能够获得音乐文件夹中的文件的专辑封面,但是当音乐文件处于不同的路径时,如何获取音乐文件夹
请提出任何建议。提前致谢
答案 0 :(得分:0)
首先获取媒体商店中所有歌曲的列表。
public void getSongList() {
// retrieve song info
ContentResolver res = getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor cursor = res.query(musicUri, null, null, null,
null);
if (cursor != null && cursor.moveToFirst()) {
// get columns
int titleColumn = cursor.getColumnIndex(MediaColumns.TITLE);
int idColumn = cursor.getColumnIndex(BaseColumns._ID);
int artistColumn = cursor.getColumnIndex(AudioColumns.ARTIST);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
// add songs to list
do {
long thisId = cursor.getLong(idColumn);
String pathId = cursor.getString(column_index);
Log.d(this.getClass().getName(), "path id=" + pathId);
metaRetriver.setDataSource(pathId);
try {
art = metaRetriver.getEmbeddedPicture();
Options opt = new Options();
opt.inSampleSize = 2;
songImage = BitmapFactory .decodeByteArray(art, 0, art.length,opt);
}
catch (Exception e)
{ imgAlbumArt.setBackgroundColor(Color.GRAY);
}
String thisTitle = cursor.getString(titleColumn);
String thisArtist = cursor.getString(artistColumn);
songList.add(new Song(thisId, thisTitle, thisArtist,songImage));
} while (cursor.moveToNext());
}
然后在获得歌曲列表后,您可以使用
song.getsongImage();
Bitmap bm= BitmapFactory.decodeFile(song.getsongImage());
ImageView image=(ImageView)findViewById(song.getsongImage());
答案 1 :(得分:0)
使用此代码:)
TestTextBlock.Text = "blerg";