获取iPod库中项目的专辑年份? [英] Get album year for item in iPod library?

查看:89
本文介绍了获取iPod库中项目的专辑年份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试以下代码:

// Per albums
MPMediaQuery *albumsQuery = [MPMediaQuery albumsQuery];
NSArray *collections = [albumsQuery collections];

for (MPMediaItemCollection *collection in collections)
{
    NSDate *collectionReleaseDate = [collection valueForProperty: MPMediaItemPropertyReleaseDate];
    NSLog(@"collection release date: %@", collectionReleaseDate);

    MPMediaItem *representativeItem = [collection representativeItem];
    NSDate *representativeItemReleaseDate = [representativeItem valueForProperty: MPMediaItemPropertyReleaseDate];
    NSLog(@"representativeItem release date: %@", representativeItemReleaseDate);
}

// Just per item
MPMediaQuery *query = [[MPMediaQuery alloc] init];
NSArray *items = [query items];

for (MPMediaItem *item in items)
{
    NSDate *date = [item valueForProperty: MPMediaItemPropertyReleaseDate];
    NSLog(@"release date: %@", date);
}

在所有情况下,我获得NSDates的nil's ...
但是在iPod库中,我可以看到日期,因此必须提供信息。
获得它的正确方法是什么?

In all cases I get nil's for NSDates... But in the iPod library I can see dates, so the information must be available. What is the correct way to obtain it?

推荐答案

嗯,我想我已经弄明白了。我以为iTunes中的'Year'列对应于API中的MPMediaItemPropertyReleaseDate - 但这是错误的。我的物品实际上没有发布日期信息。

Well, I think I've figured it out. I was thinking that 'Year' column in iTunes corresponds to MPMediaItemPropertyReleaseDate in API - but it's wrong. My items actually weren't having release date info.

我还找到了如何获取'年'信息(我需要的),但不幸的是没有记录:

I also found how to obtain 'Year' information (which I needed), but unfortunately in undocumented way:

MPMediaItem *item = ...;
NSNumber *yearNumber = [item valueForProperty:@"year"];
if (yearNumber && [yearNumber isKindOfClass:[NSNumber class]])
{
    int year = [yearNumber intValue];
    if (year != 0)
    {
        // do something with year
    }
}

这篇关于获取iPod库中项目的专辑年份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆