Reputation: 1074
I'm working on an app for a band and they'd like certain features to unlock if their album or singles are in the user's music library.
Is it possible to scan the library for a specific title?(and possibly check duration as well?)
Upvotes: 3
Views: 489
Reputation: 1074
Here is a working search. This checks for a track that matches both the title and the artist name.
MPMediaPropertyPredicate *titlePredicate = [MPMediaPropertyPredicate predicateWithValue:@"Sleep The Clock Around" forProperty:MPMediaItemPropertyTitle comparisonType:MPMediaPredicateComparisonEqualTo];
MPMediaPropertyPredicate *artistPredicate = [MPMediaPropertyPredicate predicateWithValue:@"Belle & Sebastian" forProperty:MPMediaItemPropertyArtist comparisonType:MPMediaPredicateComparisonEqualTo];
MPMediaQuery *trackSearch = [[MPMediaQuery alloc] initWithFilterPredicates:[NSSet setWithObjects:titlePredicate,artistPredicate, nil]];
if(trackSearch.items.count > 0) NSLog(@"we found the track!");
Upvotes: 2
Reputation: 11754
It should be possible to do both, have a look at the iPod Library Access Programming Guide, specifically the seconds on programmatically querying the media store and the item metadata (for the duration).
Upvotes: 2