代码和注释如下:
private Cursor getCursor(String filePath) { String path = null; Cursor c = getContentResolver().query( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER); // System.out.println(c.getString(c.getColumnIndex("_data"))); if (c.moveToFirst()) { do { // 通过Cursor 获取路径,如果路径相同则break; System.out.println("////////"+filePath); path = c.getString(c .getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)); System.out.println("?????????"+path); // 查找到相同的路径则返回,此时cursorPosition 便是指向路径所指向的Cursor 便可以返 回了 if (path.equals(filePath)) { // System.out.println("audioPath = " + path); // System.out.println("filePath = " + filePath); // cursorPosition = c.getPosition(); break; } } while (c.moveToNext()); } // 这两个没有什么作用,调试的时候用 // String audioPath = c.getString(c // .getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)); // // System.out.println("audioPath = " + audioPath); return c; } private String getAlbumArt(int album_id) { String mUriAlbums = "content://media/external/audio/albums"; String[] projection = new String[] { "album_art" }; Cursor cur = this.getContentResolver().query( Uri.parse(mUriAlbums + "/" + Integer.toString(album_id)), projection, null, null, null); String album_art = null; if (cur.getCount() > 0 && cur.getColumnCount() > 0) { cur.moveToNext(); album_art = cur.getString(0); } cur.close(); cur = null; return album_art; } private void getImage(){ Cursor currentCursor = getCursor("/mnt/sdcard/"+mp3Info); int album_id = currentCursor.getInt(currentCursor .getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID)); String albumArt = getAlbumArt(album_id); Bitmap bm = null; if (albumArt == null) { mImageView.setBackgroundResource(R.drawable.staring); } else { bm = BitmapFactory.decodeFile(albumArt); BitmapDrawable bmpDraw = new BitmapDrawable(bm); mImageView.setImageDrawable(bmpDraw); } }
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索string
, cursor
, null
, system
, 专辑图片
, mediastore
, android audio
, println
android获取路径
android 获取专辑封面、android 获取专辑图片、android 音乐专辑图片、android 音乐内置相片、android 获取本地音乐,以便于您获取更多的相关知识。
时间: 2024-10-26 05:48:41