我希望我需要进行逐位比较,但我不清楚如何在Objective-C语法中完成. MPMediaType的枚举定义如下.
我需要做的是确保MPMediaItem根本不是视频,因为尽管使用我的媒体查询过滤到MPMediaTypeAnyAudio,AVAssetReader仍会阻塞视频文件.
如何确保MPMediaItem是唯一的音频类型之一?
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;
解决方法
要从音乐库中检索所有音乐曲目,请尝试:
MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithInteger:MPMediaTypeMusic] forProperty:MPMediaItemPropertyMediaType]; MPMediaQuery *query = [[MPMediaQuery alloc] init]; [query addFilterPredicate:predicate]; NSArray *items = [query items];
要检索音乐,有声读物和播客:
MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue [NSNumber numberWithInteger:MPMediaTypeMusic | MPMediaTypePodcast | MPMediaTypeAudioBook] forProperty:MPMediaItemPropertyMediaType comparisonType:MPMediaPredicateComparisonContains];