本文介绍了一旦我有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,我该如何播放歌曲?
How do i play song back once i have 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];
这篇关于一旦我有MPMediaItemPropertyPersistentID,我如何播放歌曲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!