NSArray * songs = [[NSArray alloc] initWithArray:[[MPMediaQuery songsQuery] collections]];
for (MPMediaItemCollection * item in songs){
NSString * persistentID = [[[item representativeItem] valueForProperty:MPMediaItemPropertyPersistentID] stringValue];
// Do something with it.
???
}
How do i play song back once i have MPMediaItemPropertyPersistentID?
//Your song id NSString *songID;
MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:songID forProperty:MPMediaItemPropertyPersistentID];
MPMediaQuery *mySongQuery = [[MPMediaQuery alloc] init];
//finding songs for predicate
[mySongQuery addFilterPredicate: predicate];
//add songs to queue
[musicPlayer setQueueWithQuery:mySongQuery];
[musicPlayer play];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.