나는 비슷한 질문과 답변을 다른 웹 사이트에서 이미 보았습니다. 또한 일부 장치 (CyanogenMod 7.1을 실행하는 G2X, 맞춤 ROM을 실행하는 아내의 HD2 및 Android 2.1을 실행하는 에뮬레이터)에서 작동하는 솔루션이 있습니다. 그러나 CyanogenMod를 실행하는 나의 구석에서 작동하지는 않습니다.Android에서 앨범 아트를 가져 오는 가장 강력한 방법
내 질문은 : 모든 안드로이드 기기에서 앨범 아트를 가져올 수있는 가장 강력하고 일반적인 방법은 무엇입니까? 특정 기기, 버전 또는 음악 응용 프로그램에 대한 문제는 무엇입니까? (타사 플레이어를 의미하지는 않습니다. Google 뮤직과 기존 뮤직 클라이언트를 의미합니까?) 나의 현재 코드는 다음과 같습니다 사전에
// Is this what's making my code fail on other devices?
public final Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
// This works, and well on all devices
private int[] getAlbumIds(ContentResolver contentResolver)
{
List<Integer> result = new ArrayList<Integer>();
Cursor cursor = contentResolver.query(MediaStore.Audio.Media.getContentUri("external"), new String[]{MediaStore.Audio.Media.ALBUM_ID}, null, null, null);
if (cursor.moveToFirst())
{
do{
int albumId = cursor.getInt(0);
if (!result.contains(albumId))
result.add(albumId);
} while (cursor.moveToNext());
}
int[] resultArray = new int[result.size()];
for (int i = 0; i < result.size(); i++)
resultArray[i] = result.get(i);
return resultArray;
}
// This is the bit I want to make more robust, make sure that it works on all devices
private Shader getAlbumArt(ContentResolver contentResolver, int albumId, int width, int height)
{
Uri uri = ContentUris.withAppendedId(sArtworkUri, albumId);
InputStream input = null;
try {
input = contentResolver.openInputStream(uri);
if (input == null)
return null;
Bitmap artwork = BitmapFactory.decodeStream(input);
input.close();
if (artwork == null)
return null;
Bitmap scaled = Bitmap.createScaledBitmap(artwork, width, height, true);
if (scaled == null)
return null;
if (scaled != artwork)
artwork.recycle();
artwork = scaled;
return new BitmapShader(artwork, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
감사합니다, Ananth 여기
this.이 답변에 감사드립니다 참조 URI 코드 (및 광산) 유효 항상 사용합니다? 심지어 sdcard가없는 장치에서도 가능합니까? – Ani
여기에 sdcard가 장치에 삽입 된 경우에만 uri가 필요합니다. –
대단히 감사합니다! : D –