8

I am using the Apple Media Player Framework in my application. To fetch items I am using the MPMediaQuery as described in their documents. Which works well, but when using the predefined query to retrieve all artists, I get duplicated entries for few artists.

Can somebody explain why there are duplicates? How do I suppress them?

NSArray *collections = [[MPMediaQuery artistsQuery] collections];

(And no there aren't any typos or differences in the casing in the name of the artist!)

miho
  • 11,765
  • 7
  • 42
  • 85
  • For starters, there could be some meta that causes duplication. However, to confirm this, how about creating an NSSet using the NSArray which will automatically remove all duplicates? `NSSet *uniqueArtists = [NSSet setWithArray:collections];`. See if this removes the duplicates. Otherwise there must be something that makes the artists duplicate despite same artist name. – Nandeep Mali Nov 20 '12 at 16:18
  • Poorly that's not possible, since I also want to use the sections feature of MPMediaQuery. Yep, but it would be interesting to find out what kind of meta data duplicates them and how to prevent. – miho Nov 20 '12 at 17:32
  • do you see the same duplicate artists in the music app in the artists tab? – Felix Nov 20 '12 at 22:19
  • No, there aren't any duplicates in the Music app. – miho Nov 21 '12 at 06:51

1 Answers1

5

I've noticed that this occurs only when there are albums with multiple artists.

Instead of just [MPMediaQuery artistQuery], the following pretends this behavior:

MPMediaQuery *artistsQuery = [MPMediaQuery artistsQuery];
artistsQuery.groupingType = MPMediaGroupingAlbumArtist; 
NSArray *collections = [artistQuery collection];
miho
  • 11,765
  • 7
  • 42
  • 85