繁体   English   中英

拥有MPMediaItemPropertyPersistentID后,如何播放歌曲?

[英]How do i play song back once i have MPMediaItemPropertyPersistentID?

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后,如何播放歌曲?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM