1

我已经看到可以访问音乐和播放列表,甚至可以播放它们。但是是否可以访问附在每首音乐上的统计数据?喜欢播放次数、星星、日期和收听时间?

4

1 回答 1

6

正在查询媒体库...

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;
于 2010-01-18T00:33:57.733 回答