【发布时间】:2017-04-12 10:37:00
【问题描述】:
我有这个来自 developer.android 的功能,但它无法找到所有歌曲,只有少数。请给我一些线索。
public void getAllSongs() {
ContentResolver contentResolver = getContentResolver();
Uri uri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor cursor = contentResolver.query(uri, null, null, null, null);
if (cursor == null) {
// query failed, handle error.
} else if (!cursor.moveToFirst()) {
// no media on the device
} else {
int titleColumn = cursor.getColumnIndex(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = cursor.getColumnIndex(android.provider.MediaStore.Audio.Media._ID);
do {
long thisId = cursor.getLong(idColumn);
String thisTitle = cursor.getString(titleColumn);
songs.add(thisId + "||"+thisTitle);// ...process entry...
} while (cursor.moveToNext());
}
}
【问题讨论】:
-
看看我的一个老问题,可能会对你有所帮助stackoverflow.com/questions/32703442/…
-
这是查找歌曲的好方法,但比我想要的要慢。不过谢谢你的回答
-
您没有要求查询中的任何列。见下文
-
你说得对 :D 谢谢
标签: android audio mediastore