嘿朋友我有问题我在后台使用以下内容来获取音频文件的路径:
' String [] proj = {MediaStore.MediaColumns.DATA,MediaStore.Audio.AudioColumns.TITLE,MediaStore.Audio.Media.ARTIST,MediaStore.Audio.Media.ALBUM,MediaStore.Audio.Media.ALBUM_ID,MediaStore.Audio.Media。 _ID,MediaStore.Audio.Media.DURATION}; Uri gMusicUri = Uri.parse(" content://com.google.android.music.MusicContent/audio"); // content://com.google.android.music.MusicContent/audio
Log.d("onCreate(): XX gMusicUri = %s",""+ gMusicUri);
Cursor cursor = context.getContentResolver().query(gMusicUri, proj, null, null, null);
if (cursor == null) {
// query failed, handle error.
Log.w("onCreate(): XX cursor is null"," query failed");
} else if (!cursor.moveToFirst()) {
// no media on the device
Log.w("onCreate(): XX cursor cannot move to 1st element"," no media on device");
} else {
int idColumn = cursor.getColumnIndex(MediaStore.Audio.Media._ID);
int titleColumn = cursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
int artistColumn = cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
int albumColumn = cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM);
int durationColumn = cursor.getColumnIndex(MediaStore.Audio.Media.DURATION);
int albumColumnId = cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID);
int path = cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
do {
long id = cursor.getLong(idColumn);
String title = cursor.getString(titleColumn);
String artist = cursor.getString(artistColumn);
String album = cursor.getString(albumColumn);
String albumID = cursor.getString(albumColumnId);
String durID = cursor.getString(durationColumn);
try {
String Path=getPath(context, gMusicUri);
// int idpath = cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
Log.d("Id path is this", "=="+Path);
// String songPath = cursor.getString(idpath);
//Log.w("path"+titleColumn+","+artistColumn+","+albumColumn+","+durationColumn, "" +albumColumnId);
} catch (Exception e) {
// TODO: handle exception
}
// ...process entry...
Log.i("onCreate(): XX id = %d, title = %s, artist = %s",""+ id + title + artist + "---" +album + albumID + "---"+durID);
} while (cursor.moveToNext());
}
cursor.close();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
Log.d("Error", "illegel");
e.printStackTrace();
}'
当我试图通过一些例外来获取路径时