1
plist 파일에 사용자 재생 목록을 저장하고 앱 시작시이 재생 목록을로드하려고합니다. 내 앱에 MPMediaQuery로 재생 목록로드
이
내가 저장하는 데 사용하는 코드입니다 :if (self.backgroundMusicItems) {
NSMutableArray *songsID = [[NSMutableArray alloc] initWithCapacity:0];
MPMediaItem *item;
for (item in self.backgroundMusicItems.items) {
NSNumber *songId = [item valueForProperty:MPMediaItemPropertyPersistentID];
[songsID addObject:songId];
}
NSString *documentdir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [documentdir stringByAppendingPathComponent:@"playlist.plist"];
[songsID writeToFile:filePath atomically:YES];
}
를이 내가 부하에 사용하는 코드입니다 :
NSString *documentdir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [documentdir stringByAppendingPathComponent:@"playlist.plist"];
NSArray *myArray = [[NSArray alloc] initWithContentsOfFile:filePath];
NSMutableSet *predicates = [[NSMutableSet alloc] initWithCapacity:0];
if (myArray.count > 0) {
NSNumber *songId;
for (songId in myArray) {
MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:songId forProperty:MPMediaItemPropertyPersistentID];
[predicates addObject:predicate];
}
MPMediaQuery *query = [[MPMediaQuery alloc] initWithFilterPredicates:predicates];
NSArray *mediaItems = [query items];
if (mediaItems.count > 0) [GameOptions sharedClass].backgroundMusicItems = [[MPMediaItemCollection alloc] initWithItems:mediaItems];
}
myArray의 2 개 항목 만 [쿼리 항목]을 포함 방법 반환 0 항목. 내가 틀린 곳 ?? 어떤 노래가 두 개의 서로 다른 MPMediaItemPropertyPersistentIDs 일치하는 것이 논리적으로 불가능으로 항상 0 결과를 반환합니다 - 당신은 MPMediaItemPropertyPersistentID이 song1 및 song2의 값으로 설정되어 노래를 요구하고