NSArray * songs = [[NSArray alloc] initWithArray:[[MPMediaQuery songsQuery] collections]];
for (MPMediaItemCollection * item in songs){
NSString * persistentID = [[[item representativeItem] valueForProperty:MPMediaItemPropertyPersistentID] stringValue];
// Do something with it.
???
}
Run Code Online (Sandbox Code Playgroud)
一旦我有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];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
433 次 |
最近记录: |