I've seen it's possible to access musics and playlists and even play them. But is it possible to access the statistics attached to each music? Like play count, stars, dates and times of listening?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Querying the media library...
MPMediaQuery *query = [[MPMediaQuery alloc] init];
[query addFilterPredicate: [MPMediaPropertyPredicate
predicateWithValue: @"Moribund the Squirrel"
forProperty: MPMediaItemPropertyArtist]];
// Sets the grouping type for the media query
[query setGroupingType: MPMediaGroupingAlbum];
NSArray *albums = [query collections];
for (MPMediaItemCollection *album in albums) {
MPMediaItem *representativeItem = [album representativeItem];
NSString *artistName =
[representativeItem valueForProperty: MPMediaItemPropertyArtist];
NSString *albumName =
[representativeItem valueForProperty: MPMediaItemPropertyAlbumTitle];
NSLog (@"%@ by %@", albumName, artistName);
NSArray *songs = [album items];
for (MPMediaItem *song in songs) {
NSString *songTitle =
[song valueForProperty: MPMediaItemPropertyTitle];
NSLog (@"\t\t%@", songTitle);
}
}
System Constants...
NSString *const MPMediaItemPropertyPersistentID; // filterable
NSString *const MPMediaItemPropertyMediaType; // filterable
NSString *const MPMediaItemPropertyTitle; // filterable
NSString *const MPMediaItemPropertyAlbumTitle; // filterable
NSString *const MPMediaItemPropertyArtist; // filterable
NSString *const MPMediaItemPropertyAlbumArtist; // filterable
NSString *const MPMediaItemPropertyGenre; // filterable
NSString *const MPMediaItemPropertyComposer; // filterable
NSString *const MPMediaItemPropertyPlaybackDuration;
NSString *const MPMediaItemPropertyAlbumTrackNumber;
NSString *const MPMediaItemPropertyAlbumTrackCount;
NSString *const MPMediaItemPropertyDiscNumber;
NSString *const MPMediaItemPropertyDiscCount;
NSString *const MPMediaItemPropertyArtwork;
NSString *const MPMediaItemPropertyLyrics;
NSString *const MPMediaItemPropertyIsCompilation; // filterable
NSString *const MPMediaItemPropertyPodcastTitle; // filterable
NSString *const MPMediaItemPropertyPlayCount;
NSString *const MPMediaItemPropertySkipCount;
NSString *const MPMediaItemPropertyRating;
NSString *const MPMediaItemPropertyLastPlayedDate;