NSArray * songs = [[NSArray alloc] initWithArray:[[MPMediaQuery songsQuery] collections]];

for (MPMediaItemCollection * item in songs){

    NSString * persistentID = [[[item representativeItem]             valueForProperty:MPMediaItemPropertyPersistentID] stringValue];
    // Do something with it.
    ???

}
拥有MPMediaItem属性永久ID后,如何播放歌曲?

最佳答案

//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];

关于iphone - 拥有MPMediaItem属性永久ID后,如何播放歌曲?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9186730/

10-08 21:07