代码和注释如下:

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);        }      }


更多相关文章

  1. Android下载文件保存到路径
  2. Android中手机文件储存路径
  3. android 根据视频路径获取视频缩略图
  4. java/android 统计文件夹大小及删除文件夹下所有文件和路径
  5. 获得SDCard的路径
  6. Android 保存文件路径方法
  7. 如何在Windows上设置Android环境变量/路径

随机推荐

  1. arm-linux-androideabi-ld options
  2. Android下拉列表使用方法
  3. processBitmap - java.lang.IllegalState
  4. Android(安卓)参考网站
  5. [Android] AsyncTask的使用
  6. Android双向滚动ScrollView
  7. android的几种默认路径
  8. Android的NDK开发(1)————Android(安
  9. Android(安卓)socket 工具类
  10. android 读取ini文件