【问题标题】:MPMediaQuery not returning any results when filtered with MPMediaPropertyPredicate使用 MPMediaPropertyPredicate 过滤时,MPMediaQuery 不返回任何结果
【发布时间】:2014-06-26 01:22:38
【问题描述】:

我正在构建一个 iOS 音乐播放器,出于某种原因,每当我尝试提取给定专辑中的所有歌曲以在表格视图中显示它们时,我的查询都是空的。我已经尝试对设备上的所有歌曲运行查询,它工作得非常好,但是由于某种原因,当我尝试使用媒体谓词过滤它时,没有返回任何内容:

// Pull the currently playing song's album
MPMediaItem *currentSong = [self.store currentlyPlayingSong];
NSString *album = [currentSong valueForProperty:MPMediaItemPropertyAlbumTitle];

// Begin filtering by album title
MPMediaPropertyPredicate *albumPredicate = [MPMediaPropertyPredicate predicateWithValue:album forProperty:MPMediaItemPropertyArtist comparisonType:MPMediaPredicateComparisonEqualTo];
NSSet *albumSet = [NSSet setWithObject:albumPredicate];

MPMediaQuery *albumQuery = [[MPMediaQuery alloc] initWithFilterPredicates:albumSet];
NSArray *albumSongs = [albumQuery items];
    NSLog(@"Album Songs: %@", [albumQuery items]); 

基本上,我想从当前播放的歌曲中提取专辑标题,然后将其用作过滤器。我一直在尝试使用this post 作为指导,但我似乎无法让所提出的解决方案的任何组合发挥作用。

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

    刚刚解决它...我愚蠢地犯了一个我没有注意到的错字。我在提取专辑名称,但按艺术家过滤...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-06
      • 2011-07-21
      • 2020-09-05
      • 2018-09-22
      相关资源
      最近更新 更多