Android:MediaStore 缺少艺术家和专辑
我目前正在进行的一个项目需要应用程序发现 Android 设备上的所有音轨。除了曲目之外,它还必须能够按专辑和艺术家对它们进行分组。
我找到了 MediaStore 内容提供程序,并着手创建一个数据库辅助实用程序类,以快速返回曲目、专辑和艺术家的 ID。我已经能够查询返回一些结果的媒体存储,但似乎并非所有音频信息都存储在那里。
例如,查询所有艺术家仅返回 9 个结果,但 Android 音乐播放器应用程序返回 27 个结果。
我使用以下代码来查询艺术家:
ContentResolver resolver = getContentResolver();
String[] projection = new String[]{MediaStore.Audio.ArtistColumns.ARTIST};
Uri uri = android.provider.MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
Cursor c = null;
try {
c = resolver.query(uri, projection, null, null, null);
}
catch (UnsupportedOperationException e) {
Log.e("DatabaseHelper", "query: " + e);
c = null;
}
if(c != null) {
while(c.isAfterLast() == false) {
Log.e("ARTIST", "NAME: " + cursor.getString(0));
cursor.moveToNext();
}
}
看起来媒体扫描仪(在我的设备启动时肯定会运行)没有检测到我的音频库的大部分内容。我做错了什么吗?
我只是想快速有效地找到所有音轨、音频专辑和音频艺术家。如果 MediaStore 不能帮助我,那么我担心我将不得不实现某种形式的文件扫描仪来遍历目录结构并构建我自己的数据库,但我不想这样做;)
任何想法将不胜感激。
谢谢。
A project I'm currently working on requires the application to discover all audio tracks on an android device. In addition to the tracks, it must also be able to group them by album and artist.
I found the MediaStore content provider and set about creating a database helper utility class to quickly return the IDs of tracks, albums and artists. I have been able to query the Media Store which returns some result, but it appears that not all of the audio information is stored there.
For example, querying for all artists returns only 9 results, but the Android Music Player application returns 27.
I am using the following code to query the artists:
ContentResolver resolver = getContentResolver();
String[] projection = new String[]{MediaStore.Audio.ArtistColumns.ARTIST};
Uri uri = android.provider.MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
Cursor c = null;
try {
c = resolver.query(uri, projection, null, null, null);
}
catch (UnsupportedOperationException e) {
Log.e("DatabaseHelper", "query: " + e);
c = null;
}
if(c != null) {
while(c.isAfterLast() == false) {
Log.e("ARTIST", "NAME: " + cursor.getString(0));
cursor.moveToNext();
}
}
It seems as if the Media Scanner (which is definatley run when my device boots up) is not detecting much of my audio library. Am I doing something wrong?
I am simply trying to find all audio tracks, audio albums and audio artists quickly and efficiently. If MediaStore can't help me then I fear I will have to implement some form of file scanner to traverse directory structures and build my own database, but I don't want to do that ;)
Any thoughts would be much appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许,您还应该查询 android.provider.MediaStore.Audio.Albums.INTERNAL_CONTENT_URI 以使其余部分在媒体播放器中可见。
Probably, You should also query android.provider.MediaStore.Audio.Albums.INTERNAL_CONTENT_URI to get the rest visible in media player.