是否可以通过SDK访问iPhone / iPod Touch音乐统计数据?

时间:2010-01-17 23:37:58

标签: iphone statistics ipod-touch

我已经看到可以访问音乐和播放列表甚至播放它们。但是可以访问每首音乐附带的统计数据吗?喜欢比赛计数,明星,日期和听力时间?

1 个答案:

答案 0 :(得分:6)

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;