你好 Stack Overflowers,我希望你能帮助我。
我正在尝试从特定年份(即 2002 年)获取用户 iPhone 音乐库中所有歌曲的集合。
然后我希望通过 MPMusicPlayerController 播放歌曲。
您似乎无法设置 MPMediaPropertyPredicate 来按发布日期进行过滤,我认为这排除了这一点。我真的不想做的是必须获得所有轨道发布日期的完整数组,然后迭代所有 NSDates,因为我(可能错误地)预计这对于大型库来说可能会很慢。
完成这项任务的最佳方法是什么?
提前致谢。
这就是你要找的东西。
allMedia = [MPMediaQuery songsQuery];
//MPMediaPropertyPredicate *mpp1 = [MPMediaPropertyPredicate predicateWithValue"2" forProperty:MPMediaItemPropertyRating comparisonType:MPMediaPredicateComparisonEqualTo];
//MPMediaPropertyPredicate *mpp2 = [MPMediaPropertyPredicate predicateWithValue"op" forProperty:MPMediaItemPropertyGenre comparisonType:MPMediaPredicateComparisonContains];
//[allMedia addFilterPredicate:mpp1];
//[allMedia addFilterPredicate:mpp2];
//[myPlayer setQueueWithQuery:allMedia];
NSArray *itemsFromGenericQuery = [allMedia items];
NSMutableArray *mArray = [[NSMutableArray alloc] init];
int i = 0;
int j=0;
NSLog(@"itemCount: %d",[itemsFromGenericQuery count]);
float playsQuery = sliderPlays.value;
if(playsQuery == 20){playsQuery = 10000;}
NSLog(@"sliderRating.value %f sliderPlays.value %.1f", [sliderRating value], playsQuery);
while(i++ < 1000){
int trackNumber = arc4random() % [itemsFromGenericQuery count];
MPMediaItem *song = [itemsFromGenericQuery objectAtIndex:trackNumber];
NSString *artistName = [song valueForProperty: MPMediaItemPropertyArtist];
NSString *title = [song valueForProperty: MPMediaItemPropertyTitle];
NSString *rating = [song valueForKey:MPMediaItemPropertyRating];
double length = [[song valueForProperty:MPMediaItemPropertyPlaybackDuration] doubleValue];
NSNumber *year = [song valueForProperty:MPMediaItemPropertyYear];
if ([year intValue] >= [def intValue] <= {
if(j++ > 50){break;}
NSLog (@"tracknumber: %d j: %d artistName: %@ title: %@ length: %@ year: %@ playcount: %d",trackNumber, j, artistName, title, length, rating, [playCount intValue]);
[mArray addObject:song];
}
if(i++ > 1000)break;
}
MPMediaItemCollection *itemCol = [[MPMediaItemCollection alloc] initWithItems:mArray];
[myPlayer setQueueWithItemCollection:itemCol];
[myPlayer setShuffleMode: MPMusicShuffleModeSongs];
[myPlayer setRepeatMode: MPMusicRepeatModeNone];
关于iphone - 如何从 iPhone 音乐库中获取特定年份的所有歌曲?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4143534/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |