一旦我有MPMediaItem属性PersistentID,我如何播放歌曲?

时间:2012-02-08 01:42:14

标签: iphone ios ios4

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 Property PersistentID,我该如何播放歌曲?

1 个答案:

答案 0 :(得分:5)

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