2012-02-08 10 views
1
NSArray * songs = [[NSArray alloc] initWithArray:[[MPMediaQuery songsQuery] collections]]; 

for (MPMediaItemCollection * item in songs){ 

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

} 

MPMediaItemPropertyPersistentIDを取得したら、どのように曲を再生できますか?MPMediaItemPropertyPersistentIDがあれば、私はどのように曲を再生しますか?

答えて

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]; 
関連する問題