如何使用MediaStore查询来获取艺术家没有重复? [英] How to use MediaStore query to get Artists without duplicates?
问题描述
我想用 MediaStore <让我的手机上所有的艺术家名字/ A>;我曾使整个列表,但所有的条目,由于多个环节的歌曲/艺术家重复。有没有什么办法可以使用查询来获得只能有一个,没有任何重复?
I would like to get all the artists names on my phone by using MediaStore ;Already I have the whole list but with duplicates of all entries due to multiple links songs/artists. Is there any way to use the query to get only one of each, without any duplicates?
还有就是我的查询:
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
String[] projection = {
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DURATION
};
Cursor cursor = context.getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
projection,
selection,
null,
null);
在此先感谢!
Thanks in advance !
推荐答案
使用关键字DISTINCT的查询返回非重复值 例如,查询许多音频数字时只列出专辑名称
Using the keyword DISTINCT in the query returns non duplicate values For example, listing only album names when querying many audio numbers
new String[] { "DISTINCT " + MediaStore.Audio.Playlists.Members.ALBUM_ID + " as _id"}
但我发现,你只能返回一列
but I found you can only return one column
我一直是简单,没有通过游标循环时,以下。传递的价值,你的情况艺术家,
I kept it simple and did the following when looping through the cursor. Pass the value, in your case the artist,
if (value.length() > 0) {
// check if value already exists
if (!listItems.contains(value)) {
// doesn't exist, add it
listItems.add(value);
}
}
这是一个简单的方法。 你可以看看这个在我的应用程序的播放列表管理器在谷歌播放。我用这个方法来选择艺术家,年等。
This is a simple method. You can check this out in my app Playlist Manager on Google Play. I use this technique for selecting artists, years, etc.
这篇关于如何使用MediaStore查询来获取艺术家没有重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!