我发现可以访问音乐和播放列表,甚至可以播放它们。但是是否可以访问每首音乐附带的统计数据?比如播放次数、明星、日期和收听次数?
查询媒体库...
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);
}
}
系统常数...
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;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)