【问题标题】:Getting the most played track out of the iPod library (MPMediaQuery)从 iPod 库中获取播放次数最多的曲目 (MPMediaQuery)
【发布时间】:2011-11-26 02:59:10
【问题描述】:

我需要使用我的 iPhone 应用程序从我的 iPod 库中取出 25 首播放次数最多的歌曲。我正在使用 MPMediaQuery。

一种解决方案是循环遍历所有曲目,并通过 MPMediaItemPropertyAlbumTrackCount 进行比较。但我认为那有点低效。有没有办法直接获取 Most Played items 播放列表?

【问题讨论】:

    标签: iphone ipod mpmediaquery


    【解决方案1】:

    我认为您正在寻找 MPMediaItemPropertyPlayCount 而不是 MPMediaItemPropertyAlbumTrackCount。 MPMediaItemPropertyAlbumTrackCount 是歌曲在专辑中出现的曲目编号。

    MPMediaItemPropertyPlayCount很遗憾不能用于使用 MPMediaQuery 进行查询,因为它是用户定义的属性。

    您的最佳选择是在您的应用首次打开时将所有播放次数存储在 Core Data 等数据库中,并在用户库更改时通过注册通知来更新它。

    【讨论】:

      【解决方案2】:

      您可以使用 NSSortDescriptor 对播放次数最多的歌曲进行排序

      MPMediaQuery *everything = [[MPMediaQuery alloc] init]; NSSortDescriptor *sorter = [NSSortDescriptor sortDescriptorWithKey:MPMediaItemPropertyPlayCount ascending:NO]; NSArray *sortedSongsArray = [[everything items] sortedArrayUsingDescriptors:[NSArray arrayWithObject:sorter]];

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-01-22
        • 1970-01-01
        • 2012-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多