我正在寻找存储歌曲信息然后播放特定歌曲的方法。我看过这篇文章: How do you use MPMediaItemPropertyPersistentID to play music in iPhone Music Player Framework?
如果我已经有MPMediaItemPropertyPersistentID
,我可以直接播放该歌曲而不会循环播放每首歌曲,直到找到匹配的ID?
答案 0 :(得分:1)
您不必通过循环浏览库中的所有项目来完成此操作。它可以通过MPMediaQuery完成,如下所示:
NSNumber *persistentIDNumber = [NSNumber numberWithInteger:4238475234];
MPMusicPlayerController *player = [MPMusicPlayerController applicationMusicPlayer];
MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:persistentIDNumber forProperty:MPMediaEntityPropertyPersistentID];
MPMediaQuery *query = [[MPMediaQuery alloc] init];
[query addFilterPredicate: predicate];
[player setQueueWithQuery:query];
[player prepareToPlay];
[player play];