MPMediaQuery *songQuery = [MPMediaQuery artistsQuery];
// OR
MPMediaQuery *songQuery = [MPMediaQuery songsQuery];
// local only
[songQuery addFilterPredicate:[MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithBool:NO] forProperty:MPMediaItemPropertyIsCloudItem]];
NSArray *songs = [songQuery items];
And u will retrieve a list … but music video is still here…
becoz music video is 2049 … ok u see
enum {
// audio
MPMediaTypeMusic = 1 << 0,
MPMediaTypePodcast = 1 << 1,
MPMediaTypeAudioBook = 1 << 2,
MPMediaTypeAudioITunesU = 1 << 3, // available in iOS 5.0
MPMediaTypeAnyAudio = 0x00ff,
// video (available in iOS 5.0)
MPMediaTypeMovie = 1 << 8,
MPMediaTypeTVShow = 1 << 9,
MPMediaTypeVideoPodcast = 1 << 10,
MPMediaTypeMusicVideo = 1 << 11,
MPMediaTypeVideoITunesU = 1 << 12,
MPMediaTypeAnyVideo = 0xff00,
MPMediaTypeAny = ~0
};
typedef NSInteger MPMediaType;
tht's it:
MPMediaTypeMusic: 1
MPMediaTypePodcast: 2
MPMediaTypeAudioBook: 4
MPMediaTypeAudioITunesU: 8 (iOS 5)
MPMediaTypeAnyAudio: 255
MPMediaTypeMovie: 256
MPMediaTypeTVShow: 512
MPMediaTypeVideoPodcast: 1024
MPMediaTypeMusicVideo: 2048
MPMediaTypeVideoITunesU: 4096
MPMediaTypeAnyVideo: 65280
2049 is MPMediaTypeMusicVideo + MPMediaTypeMusic
MPMediaQuery *songQuery = [MPMediaQuery artistsQuery];
OR MPMediaQuery *songQuery = [MPMediaQuery songsQuery];
OR [songQuery addFilterPredicate:[MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithInteger:MPMediaTypeMusic] forProperty:MPMediaItemPropertyMediaType]];
even add comparisonType:MPMediaPredicateComparisonEqualTo
3 methods no work ... it want mediaType contain 1
and 2049 is still here
method : filter it:
NSArray *songs = [songQuery items];
NSMutableArray *finalSongs = [NSMutableArray array];
[songs enumerateObjectsUsingBlock:^(MPMediaItem *song, NSUInteger idx, BOOL *stop) {
NSInteger mediaValue = [[song valueForProperty:MPMediaItemPropertyMediaType] integerValue];
if (mediaValue == 1)
[finalSongs addObject:song];
}];